Exemplo n.º 1
0
        public Task SendPushToUser(
            string frontendId,
            string serverKind,
            string route,
            string uid,
            object pushMsg)
        {
            return(Task.Run(() =>
            {
                var context = new CallbackContext <bool>
                {
                    t = new TaskCompletionSource <bool>(),
                    serializer = _serializer,
                };
                var handle = GCHandle.Alloc(context, GCHandleType.Normal);
                var push = new Push
                {
                    Route = route,
                    Uid = uid,
                    Data = ByteString.CopyFrom(SerializerUtils.SerializeOrRaw(pushMsg, _serializer))
                };

                unsafe
                {
                    var data = push.ToByteArray();
                    fixed(byte *p = data)
                    {
                        IntPtr pushBuffer = PitayaCluster.pitaya_buffer_new((IntPtr)p, data.Length);
                        PitayaCluster.pitaya_send_push_to_user(_pitaya, frontendId, serverKind, pushBuffer, pushCallback, GCHandle.ToIntPtr(handle));
                    }
                }

                return context.t.Task;
            }));
        }
Exemplo n.º 2
0
        public Task SendKickToUser(string frontendId, string serverKind, KickMsg kick)
        {
            return(Task.Run(() =>
            {
                var context = new CallbackContext <bool>
                {
                    t = new TaskCompletionSource <bool>(),
                    serializer = _serializer,
                };
                var handle = GCHandle.Alloc(context, GCHandleType.Normal);

                unsafe
                {
                    var data = kick.ToByteArray();
                    fixed(byte *p = data)
                    {
                        IntPtr kickBuffer = PitayaCluster.pitaya_buffer_new((IntPtr)p, data.Length);
                        PitayaCluster.pitaya_send_kick(_pitaya, frontendId, serverKind, kickBuffer, kickCallback, GCHandle.ToIntPtr(handle));
                    }
                }

                return context.t.Task;
            }));
        }
Exemplo n.º 3
0
        Task <T> DoRpc <T>(string serverId, Route route, object msg, ISerializer serializer)
        {
            return(Task.Run(() =>
            {
                if (!callbackDict.ContainsKey(typeof(T)))
                {
                    callbackDict.Add(typeof(T), new PitayaCluster.SendRpcCallback(RpcCallback <T>));
                }
                PitayaCluster.SendRpcCallback callback;
                callbackDict.TryGetValue(typeof(T), out callback);
                var context = new CallbackContext <T>
                {
                    t = new TaskCompletionSource <T>(),
                    serializer = serializer,
                };
                var handle = GCHandle.Alloc(context, GCHandleType.Normal);
                var payload = SerializerUtils.SerializeOrRaw(msg, serializer);

                unsafe
                {
                    fixed(byte *p = payload)
                    {
                        IntPtr request = PitayaCluster.pitaya_buffer_new((IntPtr)p, payload.Length);
                        PitayaCluster.pitaya_send_rpc(
                            _pitaya,
                            serverId,
                            route.ToString(),
                            request,
                            callback,
                            GCHandle.ToIntPtr(handle));
                    }
                }

                return context.t.Task;
            }));
        }