Beispiel #1
0
 /// <summary>
 ///* Attribute to mark a method as a gRPC(Global Remote Procedure Call) service, the gRPC service must have a globally unique Id and cannot be declared in scripts that have multiple instances.<br/>
 ///* In gRPC, a client or server application can directly call a method on a server or client application on a different or local machine as if it were a local object, making it easier for you to create distributed applications and services.<br/>
 ///* gRPC is based around the idea of defining a service, specifying the methods that can be called remotely with their parameters types.
 /// </summary>
 /// <param name="id">The globally unique Id of the gRPC service.</param>
 /// <param name="cacheMode">Defines how the service will be cached on the server side.</param>
 /// <param name="targetTo">These define which remote clients get your RPC call.</param>
 /// <param name="matchmakingTo">These define which matchmaking get your RPC call.</param>
 public gRPCAttribute(byte id, CacheMode cacheMode = CacheMode.None, TargetTo targetTo = TargetTo.All, MatchmakingTo matchmakingTo = MatchmakingTo.Auto)
 {
     Id            = id;
     CacheMode     = cacheMode;
     TargetTo      = targetTo;
     MatchmakingTo = matchmakingTo;
 }
Beispiel #2
0
 public static void Write(this NeutronPlayer owner, NeutronPlayer sender, NeutronStream.IWriter writer, TargetTo targetTo, MatchmakingTo matchmakingTo, Protocol protocol)
 {
     MatchmakingHelper.Internal.Redirect(owner, sender, protocol, targetTo, writer.ToArray(), MatchmakingHelper.Internal.GetPlayersByMatchmakingTo(owner, matchmakingTo));
 }
Beispiel #3
0
#pragma warning disable IDE1006
        protected void iRPCHandler(NeutronPlayer owner, NeutronPlayer sender, short viewId, byte rpcId, byte instanceId, byte[] buffer, RegisterMode registerType, TargetTo targetTo, CacheMode cache, Protocol protocol)
#pragma warning restore IDE1006
        {
            void Run((int, int, RegisterMode) key)
            {
                bool Send()
                {
                    MatchmakingTo matchmakingTo = MatchmakingTo.Auto;

                    if (targetTo == TargetTo.Me)
                    {
                        matchmakingTo = MatchmakingTo.Me;
                    }
                    using (NeutronStream stream = Neutron.PooledNetworkStreams.Pull())
                    {
                        NeutronStream.IWriter writer = stream.Writer;
                        writer.WritePacket((byte)Packet.iRPC);
                        writer.WritePacket((byte)registerType);
                        writer.Write(viewId);
                        writer.Write(rpcId);
                        writer.Write(instanceId);
                        writer.WriteNext(buffer);
                        MatchmakingHelper.Internal.AddCache(rpcId, viewId, writer, owner, cache, CachedPacket.iRPC);
                        owner.Write(sender, writer, targetTo, matchmakingTo, protocol);
                    }
                    return(true);
                }

                if (MatchmakingHelper.Server.GetNetworkObject(key, owner, out NeutronView neutronView))
                {
                    if (neutronView.iRPCs.TryGetValue((rpcId, instanceId), out RPCInvoker remoteProceduralCall))
                    {
                        try
                        {
                            iRPCAttribute iRPCAttribute = remoteProceduralCall.iRPC;
                            if (ReflectionHelper.iRPC(buffer, remoteProceduralCall, owner))
                            {
                                Send();
                            }
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Stacktrace(ex);
                        }
                    }
                    else
                    {
                        Send();
                    }
                }
Beispiel #4
0
 protected virtual void OnCustomTarget(NeutronPlayer player, NeutronPacket packet, TargetTo targetTo, NeutronPlayer[] players)
 {
     throw new NotImplementedException("Ué cara???");
 }