public void SyncMIA(Player player = null) { if (Gamemode.Game.Instance.Round is not InProgressRound) { return; } if (player == null) { List <Client> traitors = new(); foreach (Client client in Client.All) { if ((client.Pawn as Player).Team.GetType() == typeof(TraitorTeam)) { traitors.Add(client); } } RPCs.ClientAddMissingInAction(To.Multiple(traitors), this); } else { RPCs.ClientAddMissingInAction(To.Single(player), this); } }
public MethodInfo GetRPC(int id) { if (!RPCs.ContainsKey(id)) { return(null); } return(RPCs[id].Key); }
/// <summary> /// Sends the role + team and all connected additional data like logic buttons of the current Player to the given target or - if no target was provided - the player itself /// </summary> /// <param name="to">optional - The target</param> public void SendClientRole(To?to = null) { RPCs.ClientSetRole(to ?? To.Single(this), this, Role.Name); if (to == null || to.Value.ToString().Equals(Client.Name)) { SendLogicButtonsToClient(); } }
/// <summary> /// Get the RPC's of the simple networked monobehavior /// </summary> protected virtual void Reflect() { IsClearedForBuffer = true; rpcs = new Dictionary <int, KeyValuePair <MethodInfo, List <IBRPCIntercept> > >(); #if NETFX_CORE IEnumerable <MethodInfo> methods = this.GetType().GetRuntimeMethods(); #else MethodInfo[] methods = this.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); #endif foreach (MethodInfo method in methods) { BRPC[] attributes = null; #if NETFX_CORE attributes = method.GetCustomAttributes <BRPC>().ToList().ToArray(); //if (method.GetCustomAttribute<BRPC>() != null) #else attributes = method.GetCustomAttributes(typeof(BRPC), true) as BRPC[]; #endif if (attributes != null && attributes.Length != 0) { RPCs.Add(RPCs.Count, new KeyValuePair <MethodInfo, List <IBRPCIntercept> >(method, new List <IBRPCIntercept>())); foreach (BRPC brpc in attributes) { if (brpc.interceptorType == null) { continue; } object interceptor = Activator.CreateInstance(brpc.interceptorType); if (interceptor == null || !(interceptor is IBRPCIntercept)) { throw new NetworkException("The type " + brpc.interceptorType.ToString() + " does not implement IBRPCIntercept"); } RPCs[RPCs.Count - 1].Value.Add((IBRPCIntercept)interceptor); } } } }
public void DisplayMessage(Entity activator) { switch (Receiver) { case FeedEntryType.Activator: RPCs.ClientDisplayMessage(To.Single(activator), Message, Color); break; case FeedEntryType.All: RPCs.ClientDisplayMessage(To.Everyone, Message, Color); break; case FeedEntryType.Innocents: RPCs.ClientDisplayMessage(To.Multiple(TeamFunctions.GetTeam(typeof(InnocentTeam)).GetClients()), Message, Color); break; case FeedEntryType.Traitors: RPCs.ClientDisplayMessage(To.Multiple(TeamFunctions.GetTeam(typeof(TraitorTeam)).GetClients()), Message, Color); break; case FeedEntryType.Other: Team team = TeamFunctions.GetTeam(ReceiverTeamOverride); if (team != null) { RPCs.ClientDisplayMessage(To.Multiple(team.GetClients()), Message, Color); } else { Log.Warning($"Feed entry receiver value `{Receiver}` is incorrect and will not work."); } break; } }
public static void TestVote() { RPCs.ClientOpenMapSelectionMenu(); }
/// <summary> /// To Invoke an RPC on a given Networking Stream RPC /// </summary> /// <param name="stream">Networking Stream RPC to read from</param> public bool InvokeRPC(NetworkingStreamRPC stream) { lock (rpcStackMutex) { tmpRPCMapId = ObjectMapper.Map <int>(stream); if (!RPCs.ContainsKey(tmpRPCMapId)) { return(true); } stream.SetName(RPCs[tmpRPCMapId].Key.Name); List <object> args = new List <object>(); MethodInfo invoke = null; List <IBRPCIntercept> attributes = null; foreach (KeyValuePair <int, KeyValuePair <MethodInfo, List <IBRPCIntercept> > > m in RPCs) { if (m.Value.Key.Name == stream.MethodName) { invoke = m.Value.Key; attributes = m.Value.Value; break; } } int start = stream.Bytes.StartIndex(stream.ByteReadIndex); ParameterInfo[] pars = invoke.GetParameters(); foreach (ParameterInfo p in pars) { if (p.ParameterType == typeof(MessageInfo)) { args.Add(new MessageInfo(stream.RealSenderId, stream.FrameIndex)); } else { args.Add(ObjectMapper.Map(p.ParameterType, stream)); } } stream.SetArguments(args.ToArray()); if (ReferenceEquals(this, NetworkingManager.Instance)) { if (OwningNetWorker.IsServer) { if (stream.MethodName == NetworkingStreamRPC.INSTANTIATE_METHOD_NAME) { stream.Arguments[1] = stream.SetupInstantiateId(stream, start); } else if (stream.MethodName == NetworkingStreamRPC.DESTROY_METHOD_NAME) { if (OwningNetWorker.ClearBufferedInstantiateFromID((ulong)args[0])) { // Set flag if method removed instantiate IsClearedForBuffer = !stream.BufferedRPC; } } } } foreach (IBRPCIntercept interceptor in attributes) { if (!interceptor.ValidateRPC(stream)) { return(false); } } rpcStack.Add(stream); return(true); } }