Exemplo n.º 1
0
        public async Task OnJoinRoom()
        {
            try
            {
                Request request = new Request()
                {
                    UserID = 62,
                    GameID = 32,
                    RoomID = 52,
                };
                JoinExtInfo joinEx = new JoinExtInfo()
                {
                    UserID   = 62,
                    RoomID   = 52,
                    JoinType = 2,
                };
                request.CpProto = ObjectToByteString(joinEx);

                Package.Types.Frame message = new Package.Types.Frame()
                {
                    Type     = Package.Types.FrameType.CpsService,
                    Version  = 2,
                    CmdId    = (UInt32)MvsGsCmdID.MvsJoinRoomReq,
                    UserId   = 1001,
                    Reserved = 100,
                    Message  = ObjectToByteString(request),
                };
                using (var call = client.Stream(new Metadata {
                    { "ctx", "ctx" }, { "userid", "10" }
                }))
                {
                    var responseReaderTask = Task.Run(async() =>
                    {
                        while (await call.ResponseStream.MoveNext())
                        {
                            var note    = call.ResponseStream.Current;
                            Reply reply = new Reply();
                            ByteStringToObject(reply, note.Message);
                            Console.WriteLine("OnJoinRoom:receve msg:" + GetReply(reply));
                        }
                        Console.WriteLine("OnJoinRoom:response over");
                    });

                    Console.WriteLine("OnJoinRoom:send OnJoinRoom start");

                    await call.RequestStream.WriteAsync(message);

                    await call.RequestStream.CompleteAsync();

                    await responseReaderTask;
                }
            }
            catch (RpcException e)
            {
                Console.WriteLine("RPC failed", e);
                throw;
            }
        }
    /// <summary>
    /// 加入房间
    /// </summary>
    /// <param name="msg"></param>
    public override IMessage OnJoinRoom(ByteString msg)
    {
        Request request = new Request();

        ByteUtils.ByteStringToObject(request, msg);

        Reply reply = new Reply()
        {
            UserID = request.UserID,
            GameID = request.GameID,
            RoomID = request.RoomID,
            Errno  = ErrorCode.Ok,
            ErrMsg = "OnJoinRoom success"
        };

        Room room = roomMgr.GetRoom(request.RoomID);

        if (room == null)
        {
            room = roomMgr.CreateRoom(request.RoomID, request.GameID);
        }
        RoomStatus status = room.AddPlayer(request.UserID);

        if (status != RoomStatus.AddPlayerOk)
        {
            reply.Errno  = ErrorCode.InternalServerError;
            reply.ErrMsg = "DoJoinRoomV32 failed, add player failed";
        }

        Logger.Info("OnJoinRoom start, userId={0}, gameId={1}, roomId={2}", request.UserID, request.GameID, request.RoomID);

        JoinExtInfo joinEx = new JoinExtInfo();

        ByteUtils.ByteStringToObject(joinEx, request.CpProto);
        Logger.Info("OnJoinRoom JoinExtInfo, userId={0}, roomId={1}, JoinType ={2}", joinEx.UserID, joinEx.RoomID, joinEx.JoinType);

        return(reply);
    }
Exemplo n.º 3
0
    /// <summary>
    /// 加入房间
    /// </summary>
    /// <param name="msg"></param>
    public override IMessage OnJoinRoom(ByteString msg)
    {
        Request request = new Request();

        ByteUtils.ByteStringToObject(request, msg);

        Reply reply = new Reply()
        {
            UserID = request.UserID,
            GameID = request.GameID,
            RoomID = request.RoomID,
            Errno  = ErrorCode.Ok,
            ErrMsg = "OnJoinRoom success"
        };

        Logger.Info("OnJoinRoom start, userId={0}, gameId={1}, roomId={2}", request.UserID, request.GameID, request.RoomID);

        JoinExtInfo joinEx = new JoinExtInfo();

        ByteUtils.ByteStringToObject(joinEx, request.CpProto);
        Logger.Info("OnJoinRoom JoinExtInfo, userId={0}, roomId={1}, JoinType ={2}", joinEx.UserID, joinEx.RoomID, joinEx.JoinType);

        return(reply);
    }