public void Add(char Value) { if (!IsWatching) { if (MapList.Current.Contains(Value)) { lastPrefix = Value; handleValueList = MapList.Current.GetValues(Value); StartWatching(); } } else { if (handleValueList != null) { int Index = handleValueList.IndexOf(Value); if (Index > -1) { Console.WriteLine("OnHandle?.Invoke"); OnHandle?.Invoke(this, new OnHandleValueEventArgs(lastPrefix, Value)); lastPrefix = '\0'; } } StopWatching(); } buffer.Append(Value); }
public virtual Task <bool> Handle(T message) { ReceivedMessages.Add(message); OnHandle?.Invoke(message); return(Task.FromResult(ShouldSucceed)); }
public void Handle(string type, object[] args, object[] calArgs) { type = type.ToLower(); calArgs = calArgs ?? new object[] { }; Request request = Types.Find(x => x.Name == type); if (request == null) { OnHandle?.Invoke("invalid", null, null, null); SendExplicitData("invalid", calArgs, null); return; } LastType = type; RequestData sendBack; try { sendBack = request.Callback(args); } catch (Exception e) { Log.WriteLine("Whoops, looks like something happened while trying to handle a request, " + "more information available in the log file " + "-- Please contact BlockBa5her"); Log.WriteLineSilent(e.ToString()); return; } OnHandle?.Invoke(type, request, sendBack?.Error, sendBack?.Arguments); if (sendBack == null) { throw new ArgumentNullException(nameof(sendBack), "Event handler found null device"); } SendExplicitData(type, calArgs, sendBack); }
public virtual void Handle(GhostNetConnection con, GhostNetFrame frame) { SetNetHead(con, frame); if (frame.HHead == null) { return; } bool lockedMPlayer = false; if (frame.MPlayer != null) { Monitor.Enter(frame.MPlayer, ref lockedMPlayer); frame.MPlayer.IsCached = false; HandleMPlayer(con, frame); } ChunkMPlayer player; if (!PlayerMap.TryGetValue(frame.HHead.PlayerID, out player) || player == null) { // Ghost not managed - ignore the frame. Logger.Log(LogLevel.Verbose, "ghostnet-s", $"Unexpected frame from #{frame.HHead?.PlayerID.ToString() ?? "???"} ({con.ManagementEndPoint}) - no MPlayer on this connection, possibly premature"); return; } // Temporarily attach the MPlayer chunk to make player identification easier. if (frame.MPlayer == null) { frame.MPlayer = player; Monitor.Enter(frame.MPlayer, ref lockedMPlayer); frame.MPlayer.IsCached = true; } if (frame.Has <ChunkMRequest>()) { // TODO: Handle requests by client in server. frame.Remove <ChunkMRequest>(); // Prevent request from being propagated. } if (frame.Has <ChunkMEmote>()) { HandleMEmote(con, frame); } if (frame.Has <ChunkMChat>()) { HandleMChat(con, frame); } if (frame.UUpdate != null) { HandleUUpdate(con, frame); } if (frame.Has <ChunkUActionCollision>()) { HandleUActionCollision(con, frame); } // TODO: Restrict players from abusing UAudioPlay and UParticles propagation. if (frame.Has <ChunkUAudioPlay>()) { // Propagate audio to all active players in the same room. frame.PropagateU = true; } if (frame.Has <ChunkUParticles>()) { // Propagate particles to all active players in the same room. frame.PropagateU = true; } OnHandle?.Invoke(con, frame); if (frame.PropagateM) { PropagateM(frame); } else if (frame.PropagateU) { PropagateU(frame); } if (lockedMPlayer) { Monitor.Exit(frame.MPlayer); } }