private Bootstrap InitBootstrap()
        {
            var bootstrap = new Bootstrap();

            bootstrap
            .Channel <TcpSocketChannel> ()
            .Option(ChannelOption.TcpNodelay, true)
            .Option(ChannelOption.ConnectTimeout, TimeSpan.FromSeconds(3))
            .Group(new MultithreadEventLoopGroup())
            .Handler(new ActionChannelInitializer <ISocketChannel>(c => {
                var pipeline = c.Pipeline;
                pipeline.AddLast(new LoggingHandler("CLT-CONN"));
                MessageMeta meta = _msgCodecs.GetMessageMeta();

                // IdleStateHandler
                pipeline.AddLast("timeout", new IdleStateHandler(0, 0, meta.HeartbeatInterval / 1000));
                //消息前处理
                pipeline.AddLast(
                    new LengthFieldBasedFrameDecoder(
                        meta.MaxFrameLength,
                        meta.LengthFieldOffset,
                        meta.LengthFieldLength,
                        meta.LengthAdjustment,
                        meta.InitialBytesToStrip
                        )
                    );

                pipeline.AddLast(new ChannelDecodeHandler <TMessage> (_msgCodecs));
                pipeline.AddLast(new ClientChannelHandlerAdapter <TMessage> (this, this._factory));
            }));
            return(bootstrap);
        }
Example #2
0
        /**
         * ProcessUnit 向けメッセージを処理する仮想関数
         * @param	i_pMeta		メッセージメタデータ
         * @retval	ProcessUnit.MSGPROC_RET_CODE のいずれか
         */
        public override ProcessUnit.MSGPROC_RET_CODE ProcProcessUnitMessage(MessageMeta i_pMeta)
        {
            MSGPROC_RET_CODE ret = ProcessUnit.MSGPROC_RET_CODE.MSGPROC_OK;

            /*
             * Logger.MLNLOG_DEBUG( "type=0x"+ Utility.ToHex( i_pMeta.type )
             +" id=0x"+ Utility.ToHex( i_pMeta.id )
             +" sadr=0x"+ Utility.ToHex( i_pMeta.sadr )
             +" dadr=0x"+ Utility.ToHex( i_pMeta.dadr ) );
             */
            switch ((PACKET_TYPE_LIB)i_pMeta.id)
            {
            case PACKET_TYPE_LIB.PKTTYPE_CLC_DIRECT_PASSING_NOTIFY:
            {
                if (PHASE.PHASE_BATTLE_WAIT_PASS == m_Phase)
                {
                    // PUIDをサーバーに登録
                    m_RpcConnector.GetRelayConnector().RegistRequestProcessUnit();

                    SetPhase(PHASE.PHASE_BATTLE_CONNECT_RPC, Utility.GetSecond() + WAIT_TIME_CHANGE_PHASE);
                }
            } break;

            default:
            {
                // 基底クラスの処理を呼ぶ
                ret = base.ProcProcessUnitMessage(i_pMeta);
            } break;
            }

            return(ret);
        }
Example #3
0
    public NetworkPeer( )
    {
        _meta = SharedNet.Instance.MsgMeta;

        _peerConnectedMsgID = _meta.GetMessageID <gamedef.PeerConnected>();
        _peerClosedMsgID    = _meta.GetMessageID <gamedef.PeerClosed>();
    }
Example #4
0
    public NetworkPeer( )
    {
        DebugMessage = true;

        _meta = PeerManager.Instance.MsgMeta;

        MsgID_Connected    = _meta.GetMessageID <gamedef.PeerConnected>();
        MsgID_Disconnected = _meta.GetMessageID <gamedef.PeerDisconnected>();
        MsgID_ConnectError = _meta.GetMessageID <gamedef.PeerConnectError>();
        MsgID_SendError    = _meta.GetMessageID <gamedef.PeerSendError>();
        MsgID_RecvError    = _meta.GetMessageID <gamedef.PeerRecvError>();
    }
Example #5
0
        static void TestMessage()
        {
            var mm = new MessageMeta();

            MessageMetaRegister.RegisterGeneratedMeta(mm);
            var msg = mm.CreateMessageByID(33606);

            var meta = mm.GetMetaByType(msg.GetType());

            Debug.Assert(meta.ID == 33606);

            Debug.Assert(meta.SourcePeer == "client");
        }
Example #6
0
    /// <summary>
    /// 将消息注册
    /// </summary>
    /// <param name="id"></param>
    /// <param name="t"></param>
    void RegisterMessage(Type t)
    {
        if (GetByType(t) != NullMeta)
        {
            throw new Exception("重复的消息ID");
        }

        var mi = new MessageMeta(t);

        mi.id   = StringUtility.Hash(t.FullName);
        mi.type = t;

        _idmap.Add(mi.id, mi);
        _typemap.Add(t, mi);
        _namemap.Add(mi.name, mi);
    }
Example #7
0
 public static void RegisterGeneratedMeta(MessageMeta meta)
 {
     meta.RegisterMeta(new MetaInfo
     {
         Type       = typeof(MySubType),
         ID         = 33606,
         SourcePeer = "client",
         TargetPeer = "game",
     });
     meta.RegisterMeta(new MetaInfo
     {
         Type       = typeof(MyType),
         ID         = 9980,
         SourcePeer = "",
         TargetPeer = "",
     });
 }
Example #8
0
    /// <summary>
    /// 将消息注册
    /// </summary>
    /// <param name="id"></param>
    /// <param name="t"></param>
    ///
    void RegisterMessage(Type t, uint msgid)
    {
        if (GetByType(t) != NullMeta)
        {
            return;
            //throw new Exception("重复的消息ID");
        }

        var mi = new MessageMeta(t, msgid);

        mi.id   = msgid;
        mi.type = t;

        _idmap.Add(mi.id, mi);
        _typemap.Add(t, mi);
        _namemap.Add(mi.name, mi);
    }
Example #9
0
        /// <summary>
        /// 启动服务,
        /// </summary>
        /// <param name="endPoint">绑定到本地的服务地址</param>
        /// <returns></returns>
        public async Task StartAsync(EndPoint localPoint, CancellationToken token)
        {
            // 主的线程
            _bossGroup = new MultithreadEventLoopGroup(1);
            // 工作线程,默认根据CPU计算
            _workerGroup = new MultithreadEventLoopGroup();


            var bootstrap = new ServerBootstrap()
                            .Group(_bossGroup, _workerGroup)
                            .Channel <TcpServerSocketChannel>()
                            .Option(ChannelOption.SoBacklog, 128)    //NOTE: 是否可以公开更多Netty的参数
                            .Option(ChannelOption.SoReuseaddr, true) //NOTE: 端口复用
                            .Handler(new LoggingHandler("LSTN"))
                            .ChildHandler(new ActionChannelInitializer <ISocketChannel>(channel => {
                var pipeline = channel.Pipeline;

                pipeline.AddLast(new LoggingHandler("CONN"));
                MessageMeta meta = _msgCodecs.GetMessageMeta();

                // IdleStateHandler
                pipeline.AddLast("timeout", new IdleStateHandler(0, 0, meta.HeartbeatInterval / 1000 * 2));         //服务端双倍来处理

                //消息前处理
                pipeline.AddLast(
                    new LengthFieldBasedFrameDecoder(
                        meta.MaxFrameLength,
                        meta.LengthFieldOffset,
                        meta.LengthFieldLength,
                        meta.LengthAdjustment,
                        meta.InitialBytesToStrip
                        )
                    );
                //收到消息后的解码处理Handler
                pipeline.AddLast(new ChannelDecodeHandler <TMessage>(_msgCodecs));
                //业务处理Handler,即解码成功后如何处理消息的类
                pipeline.AddLast(new ServerChannelHandlerAdapter <TMessage>(this, this._factory));
            }));

            _channel = await bootstrap.BindAsync(localPoint);

            Logger.LogInformation("DotBPE RPC Server bind at {localPoint}", localPoint);
        }
Example #10
0
        public void PassBattle()
        {
            RelayConnector pRelayConnector = m_RpcConnector.GetRelayConnector();

            MessageMeta meta = new MessageMeta(
                (UInt32)MSGMETA_TYPE_LIB.MSGMETA_TYPE_LIB_PU_TOGLOBAL,
                (UInt32)mln.ROOM_HUB.MSG_ID.MSG_ID_PASS_BATTLE,
                m_RoomHubPU_PUUID,                              // dadr
                pRelayConnector.ClientID                        // sadr
                );

            // パケット内部情報セット
            EndianStream es = new EndianStream();

            es.put(m_RpcConnector.GetPUUID());
            meta.SetData(es.size(), es.getBuffer());

            // 送信
            pRelayConnector.Post(meta);
        }
Example #11
0
        public async Task StartAsync(EndPoint endPoint)
        {
            var bossGroup   = new MultithreadEventLoopGroup(1);
            var workerGroup = new MultithreadEventLoopGroup();
            var bootstrap   = new ServerBootstrap();

            bootstrap
            .Group(bossGroup, workerGroup)
            .Channel <TcpServerSocketChannel>()
            .Option(ChannelOption.SoBacklog, 100)
            .Handler(new LoggingHandler("SRV-LSTN"))
            .ChildHandler(new ActionChannelInitializer <ISocketChannel>(channel =>
            {
                var pipeline = channel.Pipeline;

                pipeline.AddLast(new LoggingHandler("SRV-CONN"));
                MessageMeta meta = _msgCodecs.GetMessageMeta();

                // IdleStateHandler
                pipeline.AddLast("timeout", new IdleStateHandler(0, 0, meta.HeartbeatInterval / 1000 * 2)); //服务端双倍来处理

                //消息前处理
                pipeline.AddLast(
                    new LengthFieldBasedFrameDecoder(
                        meta.MaxFrameLength,
                        meta.LengthFieldOffset,
                        meta.LengthFieldLength,
                        meta.LengthAdjustment,
                        meta.InitialBytesToStrip
                        )
                    );

                pipeline.AddLast(new ChannelDecodeHandler <TMessage>(_msgCodecs));
                pipeline.AddLast(new ServerChannelHandlerAdapter <TMessage>(this));
            }));

            this._channel = await bootstrap.BindAsync(endPoint);
        }
Example #12
0
 public PeerManager( )
 {
     _meta = new MessageMeta();
     _meta.Scan("gamedef");
 }
Example #13
0
        /**
         * ProcessUnit 向けメッセージを処理する仮想関数
         * @param	i_pMeta		メッセージメタデータ
         * @retval	ProcessUnit.MSGPROC_RET_CODE のいずれか
         */
        public override ProcessUnit.MSGPROC_RET_CODE ProcProcessUnitMessage(MessageMeta i_pMeta)
        {
            MSGPROC_RET_CODE ret = ProcessUnit.MSGPROC_RET_CODE.MSGPROC_OK;
            /*
            Logger.MLNLOG_DEBUG( "type=0x"+ Utility.ToHex( i_pMeta.type )
                +" id=0x"+ Utility.ToHex( i_pMeta.id )
                +" sadr=0x"+ Utility.ToHex( i_pMeta.sadr )
                +" dadr=0x"+ Utility.ToHex( i_pMeta.dadr ) );
            */
            switch ((PACKET_TYPE_LIB)i_pMeta.id)
            {
                case PACKET_TYPE_LIB.PKTTYPE_CLC_DIRECT_PASSING_NOTIFY:
                    {
                        if (PHASE.PHASE_BATTLE_WAIT_PASS == m_Phase)
                        {
                            // PUIDをサーバーに登録
                            m_RpcConnector.GetRelayConnector().RegistRequestProcessUnit();

                            SetPhase(PHASE.PHASE_BATTLE_CONNECT_RPC, Utility.GetSecond() + WAIT_TIME_CHANGE_PHASE);
                        }
                    } break;

                default:
                    {
                        // 基底クラスの処理を呼ぶ
                        ret = base.ProcProcessUnitMessage(i_pMeta);
                    } break;
            }

            return ret;
        }
Example #14
0
        public void PassBattle()
        {
            RelayConnector pRelayConnector = m_RpcConnector.GetRelayConnector();

            MessageMeta meta = new MessageMeta(
                (UInt32)MSGMETA_TYPE_LIB.MSGMETA_TYPE_LIB_PU_TOGLOBAL,
                (UInt32)mln.ROOM_HUB.MSG_ID.MSG_ID_PASS_BATTLE,
                m_RoomHubPU_PUUID,						// dadr
                pRelayConnector.ClientID	// sadr
            );

            // パケット内部情報セット
            EndianStream es = new EndianStream();
            es.put(m_RpcConnector.GetPUUID());
            meta.SetData(es.size(), es.getBuffer());

            // 送信
            pRelayConnector.Post(meta);
        }