public void Broadcast(BroadcastEventArgs e) { if (BroadcastEvent != null) { BroadcastEvent(this, e); } }
public void StateTest() { BaseWorld baseWorld = null; // TODO: 初始化为适当的值 string strText = string.Empty; // TODO: 初始化为适当的值 object state = null; // TODO: 初始化为适当的值 BroadcastEventArgs target = new BroadcastEventArgs( baseWorld, strText, state ); // TODO: 初始化为适当的值 object actual; actual = target.State; Assert.Inconclusive( "验证此测试方法的正确性。" ); }
private void OnDevicePreflightBroadcast(BroadcastEventArgs args) { if (args.RunContext == null) { Log.WriteLine(Id, "args.Broadcast = " + args.Broadcast.ToString()); } else { Log.WriteLine(Id, "args.Broadcast = " + args.Broadcast.ToString() + ", ProgramTime.Minutes = " + args.RunContext.ProgramTime.Minutes.ToString()); } }
void m_MyCmDevice_OnBroadcast(BroadcastEventArgs args) { if (args.Broadcast == Broadcast.RetentionZeroCrossed) { m_ProgramTimer.Enabled = true; m_StartTime = DateTime.Now; } if (args.Broadcast == Broadcast.Sampleend) { m_ProgramTimer.Enabled = false; } }
public void SendChatMessage(WorldObject sender, ChatMessageArgs chatMessage) { // only players receive this List <Player> players = null; lock (objectCacheLocker) { players = worldObjects.Values.OfType <Player>().ToList(); } BroadcastEventArgs args = BroadcastEventArgs.CreateChatAction(sender, chatMessage); Broadcast(args, true, Quadrant.All); }
public void AddWorldObject(WorldObject wo) { List <WorldObject> allObjects; Log($"adding {wo.Guid.Full.ToString("X")}"); lock (objectCacheLocker) { allObjects = worldObjects.Values.ToList(); if (!worldObjects.ContainsKey(wo.Guid)) { worldObjects[wo.Guid] = wo; } } var args = BroadcastEventArgs.CreateAction(BroadcastAction.AddOrUpdate, wo); Broadcast(args, true, Quadrant.All); // if this is a player, tell them about everything else we have. if (wo is Player) { // send them the initial burst of objects Log($"blasting player \"{(wo as Player).Name}\" with {allObjects.Count} objects."); Parallel.ForEach(allObjects, (o) => { if (o.Guid.IsCreature()) { if ((o as Creature).IsAlive) { (wo as Player).TrackObject(o); } } else { (wo as Player).TrackObject(o); } }); } }
private void FireBroadcast(object sender, BroadcastEventArgs e) { ClientAdapterBroadcast broadcast = e.Data; if (broadcast.Type == ClientAdapterBroadcast.Types.BroadcastType.DEALING) { DealingEngineBroadcast dealing_broadcast = broadcast.DealingBroadcast; if (dealing_broadcast.Type == DealingEngineBroadcast.Types.BroadcastType.UPDATE_STATUS) { foreach (SystemParameterData system_parameter in dealing_broadcast.SystemParameterList) { if ("send_to_fix".Equals(system_parameter.Name)) { sendToFix.Checked = "1".Equals(system_parameter.Value); splitButton.Enabled = sendToFix.Checked; return; } } } } }
private void button1_Click(object sender, EventArgs e) { //Obj.BroadCastingInfo("haha"); var danmuRawData = "{\"info\":[[0,1,25,16777215,1450888087,\"1450888075\",0,\"082b9a9b\",0],\"O_O\",[245166,\"往事如风\",0,\"0\"],[],[20,5685],[]],\"cmd\":\"DANMU_MSG\",\"roomid\":42728}"; BilibiliDM_PluginFramework.DanmakuModel danmaku = new BilibiliDM_PluginFramework.DanmakuModel(danmuRawData, 2); var danmu = new BilibiliDM_PluginFramework.ReceivedDanmakuArgs(); danmu.Danmaku = danmaku; //弹幕 //"{\"info\":[[0,1,25,16777215,1450888087,\"1450888075\",0,\"082b9a9b\",0],\"O_O\",[245166,\"往事如风\",0,\"0\"],[],[20,5685],[]],\"cmd\":\"DANMU_MSG\",\"roomid\":42728}" //礼物 //"{\"cmd\":\"SEND_GIFT\",\"data\":{\"giftName\":\"辣条\",\"num\":1,\"uname\":\"往事如风\",\"rcost\":48706,\"uid\":245166,\"top_list\":[],\"timestamp\":1450888185,\"giftId\":1,\"giftType\":0,\"action\":\"喂食\",\"super\":0,\"price\":100,\"rnd\":\"1450888075\",\"newMedal\":0,\"medal\":-1},\"roomid\":42728}" var danmaArg = new BroadcastEventArgs(danmu); Obj.BroadCastingDanmakuArgsInfo(danmaArg); }
public void RemoveWorldObject(ObjectGuid objectId, bool adjacencyMove) { WorldObject wo = null; Log($"removing {objectId.Full.ToString("X")}"); lock (objectCacheLocker) { if (this.worldObjects.ContainsKey(objectId)) { wo = this.worldObjects[objectId]; this.worldObjects.Remove(objectId); } } // suppress broadcasting when it's just an adjacency move. clients will naturally just stop // tracking stuff if they're too far, or the new landblock will broadcast to them if they're // close enough. if (!adjacencyMove && this.id.MapScope == Enum.MapScope.Outdoors && wo != null) { var args = BroadcastEventArgs.CreateAction(BroadcastAction.Delete, wo); Broadcast(args, true, Quadrant.All); } }
private void RebroadcastServerManager_ClientDisconnected(object sender, BroadcastEventArgs args) { View.ShowRebroadcastClientDisconnected(args.EndPoint.Address.ToString(), args.EndPoint.Port); }
public void BroadcastEventArgsConstructorTest() { BaseWorld baseWorld = null; // TODO: 初始化为适当的值 string strText = string.Empty; // TODO: 初始化为适当的值 object state = null; // TODO: 初始化为适当的值 BroadcastEventArgs target = new BroadcastEventArgs( baseWorld, strText, state ); Assert.Inconclusive( "TODO: 实现用来验证目标的代码" ); }
void m_Device_OnBroadcast(BroadcastEventArgs args) { String message = String.Format("Device.OnBroadcast({0}) called", args.Broadcast); m_Device.AuditMessage(AuditLevel.Normal, message); }
private void FireBroadcast(object sender, BroadcastEventArgs e) { ClientAdapterBroadcast broadcast = e.Data; if (broadcast.Type == ClientAdapterBroadcast.Types.BroadcastType.DEALING) { DealingEngineBroadcast dealingBroadcast = broadcast.DealingBroadcast; if (dealingBroadcast.Type == DealingEngineBroadcast.Types.BroadcastType.ROLLOVER) { orders.Clear(); releases.Clear(); executions.Clear(); dispatcher.RolloverCallback(new DealingEventArgs("ROLLOVER")); } foreach (OrderMessage order in dealingBroadcast.OrderList) { if (order.HasOrderData) { Order o = new Order(order.OrderData); foreach (AllocationData data in order.AllocationDataList) { o.AddAllocation(new Allocation(data)); } Update(o); } foreach (ReleaseData data in order.ReleaseDataList) { Update(new Release(data)); } foreach (ExecutionData data in order.ExecutionDataList) { Update(new Execution(data)); } } } else if (broadcast.Type == ClientAdapterBroadcast.Types.BroadcastType.MARKETDATA) { MarketDataBroadcast marketDataBroadcast = broadcast.MarketdataBroadcast; if (marketDataBroadcast.Type == MarketDataBroadcast.Types.BroadcastType.PRICE) { foreach (MarketDataPriceData priceData in marketDataBroadcast.PriceDataList) { if (HasInstrument(priceData.InstrumentId)) { Instrument instrument = (Instrument)instruments[priceData.InstrumentId]; instrument.SetAttribute( DatabaseObject.LAST_PRC, Convert.ToString(priceData.LastPrc)); dispatcher.InstrumentChangedCallback( new MarketDataEventArgs(instrument)); } } } } }
/// <summary> /// handles broadcasting an event to the players in this landblock and to the proper adjacencies /// </summary> private void Broadcast(BroadcastEventArgs args, bool propogate, Quadrant quadrant) { WorldObject wo = args.Sender; List <Player> players = null; Log($"broadcasting object {args.Sender.Guid.Full.ToString("X")} - {args.ActionType}"); lock (objectCacheLocker) { players = worldObjects.Values.OfType <Player>().ToList(); } switch (args.ActionType) { case BroadcastAction.Delete: { players = players.Where(p => p.Location?.IsInQuadrant(quadrant) ?? false).ToList(); // If I am putting this in my inventory - you don't need to tell me about it. players.RemoveAll(p => p.Guid.Full == wo.GameData.ContainerId); Parallel.ForEach(players, p => p.StopTrackingObject(wo, true)); break; } case BroadcastAction.AddOrUpdate: { // supresss updating if player is out of range of world object.= being updated or created players = GetWorldObjectsInRange(wo, maxobjectRange, true).OfType <Player>().ToList(); // players never need an update of themselves players = players.Where(p => p.Guid != args.Sender.Guid).ToList(); Parallel.ForEach(players, p => p.TrackObject(wo)); break; } case BroadcastAction.LocalChat: { // supresss updating if player is out of range of world object.= being updated or created players = GetWorldObjectsInRange(wo, maxobjectRange, true).OfType <Player>().ToList(); Parallel.ForEach(players, p => p.ReceiveChat(wo, args.ChatMessage)); break; } case BroadcastAction.PlaySound: { // supresss updating if player is out of range of world object.= being updated or created players = GetWorldObjectsInRange(wo, maxobjectRange, true).OfType <Player>().ToList(); Parallel.ForEach(players, p => p.PlaySound(args.Sound, args.Sender.Guid)); break; } case BroadcastAction.PlayParticleEffect: { // supresss updating if player is out of range of world object.= being updated or created players = GetWorldObjectsInRange(wo, maxobjectRange, true).OfType <Player>().ToList(); Parallel.ForEach(players, p => p.PlayParticleEffect(args.Effect, args.Sender.Guid)); break; } case BroadcastAction.MovementEvent: { // suppress updating if player is out of range of world object.= being updated or created players = GetWorldObjectsInRange(wo, maxobjectRange, true).OfType <Player>().ToList(); Parallel.ForEach(players, p => p.SendMovementEvent(args.Motion, args.Sender)); break; } case BroadcastAction.BroadcastDeath: { // players never need an update of themselves // TODO: Filter to players in range and include adjacencies players = players.Where(p => p.Guid != args.Sender.Guid).ToList(); Parallel.ForEach(players, p => p.BroadcastPlayerDeath(args.DeathMessage.Message, args.DeathMessage.Victim, args.DeathMessage.Killer)); break; } } }
private void RebroadcastServerManager_BroadcastSent(object sender, BroadcastEventArgs args) { View.ShowRebroadcastClientServiced(args.EndPoint.Address.ToString(), args.EndPoint.Port, args.Port, args.Format, args.BytesSent); }
public void HandleParticleEffectEvent(WorldObject sender, PlayScript effect) { BroadcastEventArgs args = BroadcastEventArgs.CreateEffectAction(sender, effect); Broadcast(args, true, Quadrant.All); }
/// <summary> /// handles broadcasting an event to the players in this landblock and to the proper adjacencies /// </summary> private void Broadcast(BroadcastEventArgs args, bool propogate, Quadrant quadrant) { WorldObject wo = args.Sender; List <Player> players = null; Log($"broadcasting object {args.Sender.Guid.Full.ToString("X")} - {args.ActionType}"); lock (objectCacheLocker) { players = this.worldObjects.Values.OfType <Player>().ToList(); } // filter to applicable players players = players.Where(p => p.Location?.IsInQuadrant(quadrant) ?? false).ToList(); switch (args.ActionType) { case BroadcastAction.Delete: { Parallel.ForEach(players, p => p.StopTrackingObject(wo)); break; } case BroadcastAction.AddOrUpdate: { // players never need an update of themselves players = players.Where(p => p.Guid != args.Sender.Guid).ToList(); Parallel.ForEach(players, p => p.TrackObject(wo)); break; } case BroadcastAction.LocalChat: { // TODO: implement range dectection for chat events Parallel.ForEach(players, p => p.ReceiveChat(wo, args.ChatMessage)); break; } case BroadcastAction.PlaySound: { Parallel.ForEach(players, p => p.PlaySound(args.Sound, args.Sender.Guid)); break; } case BroadcastAction.PlayParticleEffect: { Parallel.ForEach(players, p => p.PlayParticleEffect(args.Effect, args.Sender.Guid)); break; } case BroadcastAction.MovementEvent: { Parallel.ForEach(players, p => p.SendMovementEvent(args.Motion, args.Sender)); break; } } // short circuit when there's no functional adjacency if (!propogate || wo?.Location?.LandblockId.MapScope != Enum.MapScope.Outdoors) { return; } if (propogate) { Log($"propogating broadcasting object {args.Sender.Guid.Full.ToString("X")} - {args.ActionType} to adjacencies"); if (wo.Location.PositionX < adjacencyLoadRange) { WestAdjacency?.Broadcast(args, false, Quadrant.NorthEast | Quadrant.SouthEast); if (wo.Location.PositionY < adjacencyLoadRange) { SouthWestAdjacency?.Broadcast(args, false, Quadrant.NorthEast); } if (wo.Location.PositionY > (maxXY - adjacencyLoadRange)) { NorthWestAdjacency?.Broadcast(args, false, Quadrant.SouthEast); } } if (wo.Location.PositionY < adjacencyLoadRange) { SouthAdjacency?.Broadcast(args, false, Quadrant.NorthEast | Quadrant.NorthWest); } if (wo.Location.PositionX > (maxXY - adjacencyLoadRange)) { EastAdjacency?.Broadcast(args, false, Quadrant.NorthWest | Quadrant.SouthWest); if (wo.Location.PositionY < adjacencyLoadRange) { SouthEastAdjacency?.Broadcast(args, false, Quadrant.NorthWest); } if (wo.Location.PositionY > (maxXY - adjacencyLoadRange)) { NorthEastAdjacency?.Broadcast(args, false, Quadrant.SouthWest); } } if (wo.Location.PositionY > (maxXY - adjacencyLoadRange)) { NorthAdjacency?.Broadcast(args, false, Quadrant.SouthEast | Quadrant.SouthWest); } } }
/// <summary> /// main game loop /// </summary> public void UseTime() { while (running) { // here we'd move server objects in motion (subject to landscape) and do physics collision detection // for now, we'll move players around List <WorldObject> movedObjects = null; List <Player> players = null; lock (objectCacheLocker) { movedObjects = this.worldObjects.Values.OfType <WorldObject>().ToList(); players = this.worldObjects.Values.OfType <Player>().ToList(); } movedObjects = movedObjects.Where(p => p.LastUpdatedTicks >= p.LastMovementBroadcastTicks).ToList(); // flag them as updated now in order to reduce chance of missing an update movedObjects.ForEach(m => m.LastMovementBroadcastTicks = WorldManager.PortalYearTicks); if (this.id.MapScope == Enum.MapScope.Outdoors) { // check to see if a player or other mutable object "roamed" to an adjacent landblock var objectsToRelocate = movedObjects.Where(m => m.Location.LandblockId.IsAdjacentTo(this.id) && m.Location.LandblockId != this.id).ToList(); // so, these objects moved to an adjacent block. they could have recalled to that block, died and bounced to a lifestone on that block, or // just simply walked accross the border line. in any case, we won't delete them, we'll just transfer them. the trick, though, is to // figure out how to treat it in adjacent landblocks. if the player walks across the southern border, the north adjacency needs to remove // them, but the south is actually getting them. we need to avoid sending Delete+Create to clients that already know about it, though. objectsToRelocate.ForEach(o => Log($"attempting to relocate object {o.Name} ({o.Guid.Full.ToString("X")})")); // RelocateObject will put them in the right landblock objectsToRelocate.ForEach(o => LandblockManager.RelocateObject(o)); // Remove has logic to make sure it doesn't double up the delete+create when "true" is passed. objectsToRelocate.ForEach(o => RemoveWorldObject(o.Guid, true)); } // broadcast Parallel.ForEach(movedObjects, mo => { if (mo.Location.LandblockId == this.id) { // update if it's still here Broadcast(BroadcastEventArgs.CreateAction(BroadcastAction.AddOrUpdate, mo), true, Quadrant.All); } else { // remove and readd if it's not this.RemoveWorldObject(mo.Guid, false); LandblockManager.AddObject(mo); } }); // TODO: figure out if this landblock can be unloaded // process player action queues foreach (Player p in players) { QueuedGameAction action = p.ActionQueuePop(); if (action != null) { HandleGameAction(action, p); } } Thread.Sleep(1); } // TODO: release resources }
/// <summary> /// Raised when a broadcast provider sends some bytes to a client. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void BroadcastProvider_BroadcastSent(object sender, BroadcastEventArgs args) { OnBroadcastSent(args); }
public void HandleSoundEvent(WorldObject sender, Sound soundEvent) { BroadcastEventArgs args = BroadcastEventArgs.CreateSoundAction(sender, soundEvent); Broadcast(args, true, Quadrant.All); }
/// <summary> /// Raised when a client disconnects from a broadcast provider. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void BroadcastProvider_ClientDisconnected(object sender, BroadcastEventArgs args) { OnClientDisconnected(args); }
public void HandleMovementEvent(WorldObject sender, UniversalMotion motion) { BroadcastEventArgs args = BroadcastEventArgs.CreateMovementEvent(sender, motion); Broadcast(args, true, Quadrant.All); }
private void OnDeviceBroadcast(BroadcastEventArgs args) { Log.WriteLine(Id, "args.Broadcast = " + args.Broadcast.ToString()); // args.RunContext is always null switch (args.Broadcast) { case Broadcast.Inject: { break; } case Broadcast.Hold: // Pause { // Can be caused by: // - Wait <boolean condition> (in Instrument Method) // - Message displayed to the user // - Sampler.Inject // - System.Hold // The clock that controls script execution is paused and no more script lines are processed for the time being. // Pump drivers need to inform the firmware that it should temporarily pause gradient execution and // flow /composition should remain unchanged for the time being (if there is a change in progress). break; } case Broadcast.Continue: // Resume { // Can be caused by: // - Wait resolves when <boolean condition> becomes true // - User has confirmed message that has been displayed // - Sampler driver has notified system about the inject response // - System.Continue // Resume changing flow/composition where it left off (if there is a change in progress). break; } case Broadcast.Stopflow: // Can be caused by: System.Stopflow { // Do whatever is done on Broadcast.Hold and set Flow = 0 if (IsSimulated) { Flow = 0; } break; } case Broadcast.InjectResponse: { //if (m_IsRamped) SendStartCommand(); break; } case Broadcast.InjectBlankRun: { //if (m_IsRamped) SendStartCommand(); break; } case Broadcast.RetentionZeroCrossed: { //if (m_IsRamped) SendStartCommand(); break; } case Broadcast.AbortRequested: { //SendAbortCommand(); break; } case Broadcast.AbortError: { //SendAbortCommand(); break; } default: break; } }
public void HandleDeathMessage(WorldObject sender, DeathMessageArgs deathMessageArgs) { BroadcastEventArgs args = BroadcastEventArgs.CreateDeathMessage(sender, deathMessageArgs); Broadcast(args, false, Quadrant.All); }
private void OnPfBroadcast(BroadcastEventArgs args) { m_MyCmDevice.AuditMessage(AuditLevel.Warning, args.RunContext.ProgramTime.Minutes.ToString() + " min: OnPreflightBroadcast handler OnPfBroadcast(" + args.Broadcast.ToString() + ")"); }
/// <summary> /// main game loop /// </summary> public void UseTime() { while (running) { // here we'd move server objects in motion (subject to landscape) and do physics collision detection List <WorldObject> allworldobj = null; List <Player> allplayers = null; List <Creature> allcreatures = null; List <WorldObject> movedObjects = null; List <WorldObject> despawnObjects = null; List <Creature> deadCreatures = null; lock (objectCacheLocker) { allworldobj = worldObjects.Values.ToList(); } // all players on this land block allplayers = allworldobj.OfType <Player>().ToList(); allcreatures = allworldobj.OfType <Creature>().ToList(); despawnObjects = allworldobj.ToList(); despawnObjects = despawnObjects.Where(x => x.DespawnTime > -1).ToList(); deadCreatures = allworldobj.OfType <Creature>().ToList(); deadCreatures = deadCreatures.Where(x => x.IsAlive == false).ToList(); // flag them as updated now in order to reduce chance of missing an update // this is only for moving objects across landblocks. movedObjects = allworldobj.ToList(); movedObjects = movedObjects.Where(p => p.LastUpdatedTicks >= p.LastMovementBroadcastTicks).ToList(); movedObjects.ForEach(m => m.LastMovementBroadcastTicks = WorldManager.PortalYearTicks); if (id.MapScope == Enum.MapScope.Outdoors) { // check to see if a player or other mutable object "roamed" to an adjacent landblock var objectsToRelocate = movedObjects.Where(m => m.Location.LandblockId.IsAdjacentTo(id) && m.Location.LandblockId != id).ToList(); // so, these objects moved to an adjacent block. they could have recalled to that block, died and bounced to a lifestone on that block, or // just simply walked accross the border line. in any case, we won't delete them, we'll just transfer them. the trick, though, is to // figure out how to treat it in adjacent landblocks. if the player walks across the southern border, the north adjacency needs to remove // them, but the south is actually getting them. we need to avoid sending Delete+Create to clients that already know about it, though. objectsToRelocate.ForEach(o => Log($"attempting to relocate object {o.Name} ({o.Guid.Full.ToString("X")})")); // RelocateObject will put them in the right landblock objectsToRelocate.ForEach(o => LandblockManager.RelocateObject(o)); // Remove has logic to make sure it doesn't double up the delete+create when "true" is passed. objectsToRelocate.ForEach(o => RemoveWorldObject(o.Guid, true)); } // for all players on landblock. Parallel.ForEach(allplayers, player => { // Process Action Queue for player. QueuedGameAction action = player.ActionQueuePop(); if (action != null) { HandleGameAction(action, player); } // Process Examination Queue for player QueuedGameAction examination = player.ExaminationQueuePop(); if (examination != null) { HandleGameAction(examination, player); } }); UpdateStatus(allplayers.Count); double tickTime = WorldManager.PortalYearTicks; // per-creature update on landblock. Parallel.ForEach(allworldobj, wo => { // Process the creatures wo.Tick(tickTime); }); // broadcast moving objects to the world.. // players and creatures can move. Parallel.ForEach(movedObjects, mo => { // detect all world objects in ghost range List <WorldObject> woproxghost = new List <WorldObject>(); woproxghost.AddRange(GetWorldObjectsInRange(mo, maxobjectGhostRange, true)); // for all objects in rang of this moving object or in ghost range of moving object update them. Parallel.ForEach(woproxghost, wo => { if (mo.Guid.IsPlayer()) { // if world object is in active zone then. if (wo.Location.SquaredDistanceTo(mo.Location) <= maxobjectRange) { // if world object is in active zone. if (!(mo as Player).GetTrackedObjectGuids().Contains(wo.Guid)) { (mo as Player).TrackObject(wo); } } // if world object is in ghost zone and outside of active zone else if ((mo as Player).GetTrackedObjectGuids().Contains(wo.Guid)) { (mo as Player).StopTrackingObject(wo, true); } } }); if (mo.Location.LandblockId == id) { // update if it's still here Broadcast(BroadcastEventArgs.CreateAction(BroadcastAction.AddOrUpdate, mo), true, Quadrant.All); } else { // remove and readd if it's not RemoveWorldObject(mo.Guid, false); LandblockManager.AddObject(mo); } }); // despawn objects despawnObjects.ForEach(deo => { if (deo.DespawnTime < WorldManager.PortalYearTicks) { RemoveWorldObject(deo.Guid, false); } }); // respawn creatures deadCreatures.ForEach(dc => { if (dc.RespawnTime < WorldManager.PortalYearTicks) { dc.IsAlive = true; // HandleParticleEffectEvent(dc, PlayScript.Create); AddWorldObject(dc); } }); Thread.Sleep(1); } // TODO: release resources }
void broadcastHandler(BroadcastEventArgs args) { switch (args.Command) { case "PopupWidget": Widget widget = (args.Object as Widget); if (widget != null) tray.PopupWidget (widget); break; case "StopTimer": if (tray.Popup != null) tray.Popup.StopTimer (); break; case "StartTimer": if (tray.Popup != null) tray.Popup.StartTimer (); break; } }