Exemplo n.º 1
0
        public async Task Handle(Session session, Entity entity, ActorRequest message)
        {
            if (message.AMessage is AFrameMessage aFrameMessage)
            {
                // 客户端发送不需要设置Frame消息的id,在这里统一设置,防止客户端被破解发个假的id过来
                aFrameMessage.Id = entity.Id;
                Unit unit = entity as Unit;

                MatchRoomComponent roomComponent = Game.Scene.GetComponent <MatchRoomComponent>();
                MatchRoom          matchroom     = roomComponent.Get(unit.RoomID);
                if (matchroom != null)
                {
                    matchroom.Add(aFrameMessage);
                }

                //Game.Scene.GetComponent<ServerFrameComponent>().Add(aFrameMessage);
                ActorResponse response = new ActorResponse
                {
                    RpcId = message.RpcId
                };
                session.Reply(response);
                return;
            }
            await Game.Scene.GetComponent <ActorMessageDispatherComponent>().Handle(session, entity, message);
        }
 public async Task Handle(Session session, Entity entity, ActorRequest actorRequest)
 {
     OpcodeTypeComponent opcodeTypeComponent = session.Network.Entity.GetComponent <OpcodeTypeComponent>();
     Type     type    = opcodeTypeComponent.GetType(actorRequest.Op);
     IMessage message = (IMessage)session.Network.MessagePacker.DeserializeFrom(type, actorRequest.AMessage);
     await Game.Scene.GetComponent <ActorMessageDispatherComponent>().Handle(session, entity, actorRequest, message);
 }
Exemplo n.º 3
0
        public async Task Handle(Session session, Entity entity, ActorRequest actorRequest)
        {
            ActorResponse actorResponse = new ActorResponse();

            actorResponse.RpcId = actorRequest.RpcId;

            try
            {
                OpcodeTypeComponent opcodeTypeComponent = session.Network.Entity.GetComponent <OpcodeTypeComponent>();
                Type     type    = opcodeTypeComponent.GetType(actorRequest.Op);
                IMessage message = (IMessage)session.Network.MessagePacker.DeserializeFrom(type, actorRequest.AMessage);

                // 发送给客户端
                Session clientSession = entity as Session;
                clientSession.Send(actorResponse.Flag, message);

                session.Reply(actorResponse);
                await Task.CompletedTask;
            }
            catch (Exception e)
            {
                actorResponse.Error   = ErrorCode.ERR_SessionActorError;
                actorResponse.Message = $"session actor error {e}";
                session.Reply(actorResponse);
                throw;
            }
        }
 public IActionResult Put([FromBody] ActorRequest actor)
 {
     if (_actorsService.UpdateActor(AutoMapper.Mapper.Map <Actor>(actor)))
     {
         return(NoContent());
     }
     return(BadRequest());
 }
Exemplo n.º 5
0
 public async Task Handle(Session session, Entity entity, ActorRequest message)
 {
     if (message.AMessage is AFrameMessage aFrameMessage)
     {
         Game.Scene.GetComponent <ServerFrameComponent>().Add(aFrameMessage);
     }
     await Game.Scene.GetComponent <ActorMessageDispatherComponent>().Handle(session, entity, message);
 }
Exemplo n.º 6
0
        public IActionResult Post([FromBody] ActorRequest actorRequest)
        {
            if (!_actorService.AddActorsToMovie(AutoMapper.Mapper.Map <Actor>(actorRequest)))
            {
                return(BadRequest());
            }

            return(Ok());
        }
Exemplo n.º 7
0
        public void Put(int actorId, ActorRequest request)
        {
            Actor actorEdit = Actors.FirstOrDefault(b => b.Id == actorId);

            if (actorEdit == null)
            {
                throw new ArgumentException("Ator não existe");
            }
            actorEdit.Name = request.Name;
        }
Exemplo n.º 8
0
        public async Task Handle(Session session, Entity entity, ActorRequest message)
        {
            ((Session)entity).Send(message.AMessage);
            ActorResponse response = new ActorResponse
            {
                RpcId = message.RpcId
            };

            session.Reply(response);
        }
Exemplo n.º 9
0
        public ActorDTO UpdateActor(int id, ActorRequest actorRequest)
        {
            var actor = GetActorEntityById(id);

            actor.Name   = actorRequest.Name;
            actor.Avatar = actorRequest.Avatar;

            dbContext.Update(actor);
            Save();
            return(new ActorDTO(actor));
        }
Exemplo n.º 10
0
        public ActorDTO CreateActor(ActorRequest actorRequest)
        {
            var actor = new Actor()
            {
                Name   = actorRequest.Name,
                Avatar = actorRequest.Avatar,
            };

            dbContext.Add(actor);
            Save();
            return(new ActorDTO(actor));
        }
Exemplo n.º 11
0
 public ActionResult <int> Post(ActorRequest request)
 {
     try
     {
         int newactorId = actorService.Post(request);
         return(Ok(newactorId));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
Exemplo n.º 12
0
        public int Post(ActorRequest request)
        {
            int newId = Actors.Count + 1;

            Actors.Add(new Actor()
            {
                Id   = newId,
                Name = request.Name
            });

            return(newId);
        }
Exemplo n.º 13
0
 public async Task Handle(Session session, Entity entity, uint rpcId, ActorRequest message)
 {
     if (message.AMessage is IFrameMessage aFrameMessage)
     {
         // 客户端发送不需要设置Frame消息的id,在这里统一设置,防止客户端被破解发个假的id过来
         aFrameMessage.Id = entity.Id;
         Game.Scene.GetComponent <ServerFrameComponent>().Add(aFrameMessage);
         ActorResponse response = new ActorResponse();
         session.Reply(rpcId, response);
         return;
     }
     await Game.Scene.GetComponent <ActorMessageDispatherComponent>().Handle(session, entity, rpcId, message);
 }
Exemplo n.º 14
0
 public ActionResult Put(int id, ActorRequest request)
 {
     try
     {
         actorService.Put(id, request);
         return(Ok("ator editado com sucesso"));
     }
     catch (ArgumentException ex)
     {
         return(NotFound(ex.Message));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
        public async Task Handle(Session session, Entity entity, ActorRequest actorRequest)
        {
            OpcodeTypeComponent opcodeTypeComponent = session.Network.Entity.GetComponent <OpcodeTypeComponent>();
            Type     type    = opcodeTypeComponent.GetType(actorRequest.Op);
            IMessage message = (IMessage)session.Network.MessagePacker.DeserializeFrom(type, actorRequest.AMessage);

            if (message is OneFrameMessage aFrameMessage)
            {
                Game.Scene.GetComponent <ServerFrameComponent>().Add(aFrameMessage);

                ActorResponse actorResponse = new ActorResponse();
                actorResponse.RpcId = actorRequest.RpcId;
                session.Reply(actorResponse);
                return;
            }
            await Game.Scene.GetComponent <ActorMessageDispatherComponent>().Handle(session, entity, actorRequest, message);
        }
Exemplo n.º 16
0
        public async Task Handle(Session session, Entity entity, uint rpcId, ActorRequest message)
        {
            ActorResponse response = new ActorResponse();

            try
            {
                ((Session)entity).Send((IMessage)message.AMessage);
                session.Reply(rpcId, response);
                await Task.CompletedTask;
            }
            catch (Exception e)
            {
                response.Error   = ErrorCode.ERR_SessionActorError;
                response.Message = $"session actor error {e}";
                session.Reply(rpcId, response);
                throw;
            }
        }
        //[Authorize(Roles = Authorize.Admin)]
        public IActionResult Put(int id, [FromBody] ActorRequest actorRequest)
        {
            if (actorRequest == null)
            {
                return(StatusCode(400, ModelState));
            }
            if (!ModelState.IsValid)
            {
                return(StatusCode(400, ModelState));
            }

            try
            {
                var actor = actorRepository.UpdateActor(id, actorRequest);
                return(Ok(actor));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 18
0
        private HttpWebRequest SendRequest(IRequestTarget target, RequestMessage requestMessage)
        {
            var actorId = ((SlimActorTarget)target).Id;
            var uri     = new Uri(Root, "/actor/" + actorId);

            var httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            var actorRequest = new ActorRequest
            {
                RequestId   = ++_lastRequestId,
                MessageType = requestMessage.InvokePayload.GetType().FullName,
                MessageData = JObject.Parse(JsonConvert.SerializeObject(requestMessage.InvokePayload))
            };

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(JsonConvert.SerializeObject(actorRequest));
            }

            return(httpWebRequest);
        }
Exemplo n.º 19
0
 public async Task Handle(Session session, Entity entity, ActorRequest message)
 {
     await Game.Scene.GetComponent <ActorMessageDispatherComponent>().Handle(session, entity, message);
 }
Exemplo n.º 20
0
 public ProductInfo ActorSearchRequest(ActorRequest ActorSearchRequest)
 {
     object[] results = this.Invoke("ActorSearchRequest", new object[] {
         ActorSearchRequest});
     return ((ProductInfo)(results[0]));
 }
Exemplo n.º 21
0
        public async Task <HttpResponseMessage> Actor(string id, ActorRequest request)
        {
            // Get Message

            IInterfacedPayload message;

            try
            {
                var jsonText = await Request.Content.ReadAsStringAsync();

                var json = JObject.Parse(jsonText);

                var type = TypeUtility.GetType(request.MessageType);
                if (type == null)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               "Cannot find message type: " + request.MessageType));
                }

                message = (IInterfacedPayload)Activator.CreateInstance(type);
                JsonConvert.PopulateObject(request.MessageData.ToString(), message);

                Console.WriteLine("* Actor({0}) <- {1} {2}", id, type.Name, request.MessageData.ToString(Formatting.None));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(
                           HttpStatusCode.BadRequest,
                           e.ToString()));
            }

            // Try to send message to actor

            IActorRef actor;

            try
            {
                actor = await Program.System.ActorSelection("/user/" + id).ResolveOne(TimeSpan.Zero);
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, "Actor not found: " + e));
            }

            if (request.RequestId != 0)
            {
                var reply = await actor.Ask <ResponseMessage>(new RequestMessage
                {
                    RequestId     = request.RequestId,
                    InvokePayload = message
                });

                if (reply != null)
                {
                    var reply2 = new ActorReply {
                        RequestId = reply.RequestId
                    };
                    if (reply.Exception != null)
                    {
                        reply2.Exception = reply.Exception;
                        Console.WriteLine("* Actor({0}) -> {1}", id, reply.Exception);
                    }
                    else if (reply.ReturnPayload != null)
                    {
                        reply2.ResultType = reply.ReturnPayload.GetType().FullName;
                        var value = reply.ReturnPayload.Value;
                        if (value != null)
                        {
                            reply2.ResultData = JToken.FromObject(value);
                            Console.WriteLine("* Actor({0}) -> {1} {2}", id, reply.ReturnPayload.GetType().Name, reply2.ResultData.ToString(Formatting.None));
                        }
                        else
                        {
                            Console.WriteLine("* Actor({0}) -> null", id);
                        }
                    }
                    else
                    {
                        Console.WriteLine("* Actor({0}) -> void", id);
                    }
                    return(Request.CreateResponse(HttpStatusCode.OK, reply2));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "?"));
                }
            }
            else
            {
                actor.Tell(new RequestMessage {
                    InvokePayload = message
                });
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
        }
Exemplo n.º 22
0
        public async Task <IActionResult> Post([FromBody] ActorRequest actor)
        {
            await _actorsService.AddNewActor(AutoMapper.Mapper.Map <Actor>(actor));

            return(Ok());
        }
 public IActionResult Post([FromBody] ActorRequest actor)
 {
     _actorsService.AddNewActor(AutoMapper.Mapper.Map <Actor>(actor));
     return(Ok());
 }
Exemplo n.º 24
0
 public System.IAsyncResult BeginActorSearchRequest(ActorRequest ActorSearchRequest, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("ActorSearchRequest", new object[] {
         ActorSearchRequest}, callback, asyncState);
 }
Exemplo n.º 25
0
        public async Task<HttpResponseMessage> Actor(string id, ActorRequest request)
        {
            // Get Message

            IInterfacedPayload message;
            try
            {
                var jsonText = await Request.Content.ReadAsStringAsync();
                var json = JObject.Parse(jsonText);

                var type = TypeUtility.GetType(request.MessageType);
                if (type == null)
                {
                    return Request.CreateResponse(
                        HttpStatusCode.BadRequest,
                        "Cannot find message type: " + request.MessageType);
                }

                message = (IInterfacedPayload)Activator.CreateInstance(type);
                JsonConvert.PopulateObject(request.MessageData.ToString(), message);

                Console.WriteLine("* Actor({0}) <- {1} {2}", id, type.Name, request.MessageData.ToString(Formatting.None));
            }
            catch (Exception e)
            {
                return Request.CreateResponse(
                    HttpStatusCode.BadRequest,
                    e.ToString());
            }

            // Try to send message to actor

            IActorRef actor;
            try
            {
                actor = await Program.System.ActorSelection("/user/" + id).ResolveOne(TimeSpan.Zero);
            }
            catch (Exception e)
            {
                return Request.CreateResponse(HttpStatusCode.NotFound, "Actor not found: " + e);
            }

            if (request.RequestId != 0)
            {
                var reply = await actor.Ask<ResponseMessage>(new RequestMessage
                {
                    RequestId = request.RequestId,
                    InvokePayload = message
                });
                if (reply != null)
                {
                    var reply2 = new ActorReply { RequestId = reply.RequestId };
                    if (reply.Exception != null)
                    {
                        reply2.Exception = reply.Exception;
                        Console.WriteLine("* Actor({0}) -> {1}", id, reply.Exception);
                    }
                    else if (reply.ReturnPayload != null)
                    {
                        reply2.ResultType = reply.ReturnPayload.GetType().FullName;
                        var value = reply.ReturnPayload.Value;
                        if (value != null)
                        {
                            reply2.ResultData = JToken.FromObject(value);
                            Console.WriteLine("* Actor({0}) -> {1} {2}", id, reply.ReturnPayload.GetType().Name, reply2.ResultData.ToString(Formatting.None));
                        }
                        else
                        {
                            Console.WriteLine("* Actor({0}) -> null", id);
                        }
                    }
                    else
                    {
                        Console.WriteLine("* Actor({0}) -> void", id);
                    }
                    return Request.CreateResponse(HttpStatusCode.OK, reply2);
                }
                else
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, "?");
                }
            }
            else
            {
                actor.Tell(new RequestMessage { InvokePayload = message });
                return Request.CreateResponse(HttpStatusCode.OK);
            }
        }
Exemplo n.º 26
0
 public Task <ActorResponse> Send(ActorRequest request, CancellationToken token)
 {
     return(this.Mediator.Send(request, token));
 }