Esempio n. 1
0
        public void DeleteRelayConnector()
        {
            if (null == this.m_pRelayConnector)
            {
                return;
            }

            if (null != m_pRpcClient)
            {
                m_pRpcClient.DeleteConnectionBySrcPUUID(m_pRelayConnector.SendPUUID);
            }

            if (null != m_pProcessUnitBank)
            {
                m_pProcessUnitBank.RemoveProcessUnitReal(m_PUUID);
            }

            if (null != m_pSocketManager)
            {
                UInt32     socketId = this.m_pRelayConnector.SocketID;
                BaseSocket pSocket  = m_pSocketManager.GetSocketFromID(socketId);
                if (null != pSocket)
                {
                    m_pSocketManager.DeleteSocket(pSocket);
                    pSocket = null;
                }
            }

            m_pProcessUnit.UnsetRelayConnector(this.m_pRelayConnector);

            this.m_pRelayConnector.SetProcessUnit(null);
            this.m_pRelayConnector.SetSocketManager(null);
            m_pRelayConnector = null;
        }
Esempio n. 2
0
        public IRelayConnector Connect(IRelayInput input, IRelayOutput output)
        {
            if (input == null || output == null)
            {
                return(null);
            }

            var iKey = input.Name ?? string.Empty;
            var oKey = output.Name ?? string.Empty;

            if (!_inputInitializer.TryGetValue(iKey, out var inputInitializer))
            {
                _inputInitializer.Add(iKey, inputInitializer = new InputInitializer(iKey, input, _queue, RemoveInputInitializer));
            }

            if (!_outputInitializer.TryGetValue(oKey, out var outputInitializer))
            {
                _outputInitializer.Add(oKey, outputInitializer = new OutputInitializer(oKey, output, RemoveOutputInitializer));
            }

            var key = $"{iKey}-{oKey}";

            if (!_connectors.TryGetValue(key, out var connector))
            {
                _connectors.Add(key, connector = new RelayConnector(key, inputInitializer, outputInitializer, _lazyInitializer, RemoveConnector));
            }

            return(connector);
        }
Esempio n. 3
0
        void Start()
        {
            m_pRelayConnector  = null;
            m_pSocketManager   = null;
            m_pProcessUnit     = null;
            m_pProcessUnitBank = null;

            m_PUUID = 0;
            m_RPCID = 0;
        }
Esempio n. 4
0
        public void NewRelayConnector()
        {
            if (null != m_pRelayConnector)
            {
                return;
            }

            m_pRelayConnector = new RelayConnector(true);
            m_pRelayConnector.SetSocketManager(m_pSocketManager);
            m_pRelayConnector.SetProcessUnit(m_pProcessUnit);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        protected override Int32 ProcUpdate()
        {
            Int32 ret = base.ProcUpdate();

            if (0 != ret)
            {
                return(ret);
            }

            UInt64 nowTime = Utility.GetSecond();

            switch (m_Phase)
            {
            case PHASE.PHASE_NONE:
            {
                if (null != m_RpcConnector.GetRelayConnector())
                {
                    SetPhase(PHASE.PHASE_WAIT_CONNECT_SERVER, 0);
                }
            } break;

            case PHASE.PHASE_WAIT_CONNECT_SERVER:
            {
                // サーバーとの接続待ち
            } break;

            case PHASE.PHASE_MATCHING_WAIT_APPOINTMENT:
            {
                // バトル予約待ち
            } break;

            case PHASE.PHASE_MATCHING_WAIT_EXIT_ROOM:
            {
                // ルーム退室待ち
            } break;

            case PHASE.PHASE_BATTLE_PASS:
            {
                if (m_RpcConnector.GetRelayConnector().IsEndSetup())
                {
                    PassBattle();

                    SetPhase(PHASE.PHASE_BATTLE_WAIT_PASS, nowTime + WAIT_TIME_CHANGE_PHASE);
                }
                else if (m_WaitTime < nowTime)
                {
                    Logger.MLNLOG_ERR("Phase Not Change Phase=" + (UInt32)m_Phase + ", CharaId=0x" + Utility.ToHex(m_CharaId));

                    SetPhase(PHASE.PHASE_BATTLE_END, 0);
                }
            } break;

            case PHASE.PHASE_BATTLE_WAIT_PASS:
            {
                if (m_WaitTime < nowTime)
                {
                    Logger.MLNLOG_ERR("Phase Not Change Phase=" + (UInt32)m_Phase + ", CharaId=0x" + Utility.ToHex(m_CharaId));

                    SetPhase(PHASE.PHASE_BATTLE_END, 0);
                }
            } break;

            case PHASE.PHASE_BATTLE_CONNECT_RPC:
            {
                RelayConnector pRelayConnector = m_RpcConnector.GetRelayConnector();
                if (ProcessUnitManager.INVALID_PUUID == pRelayConnector.SendPUUID)
                {
                    break;
                }

                // バトル子プロセスとRPC接続開始
                UInt64 rpcId = m_RpcConnector.ConnectRpc(BTL.INTFID.BATTLE, m_RpcConnector.GetPUUID(), pRelayConnector.SendPUUID, pRelayConnector.ClientID);
                Logger.MLNLOG_INFO("BattlePU Connect CharaId=0x" + Utility.ToHex(m_CharaId)
                                   + ", RPCID=0x" + Utility.ToHex(rpcId) + ", dstPUUID=0x" + Utility.ToHex(m_RpcConnector.GetPUUID())
                                   + ", srcPUUID=0x" + Utility.ToHex(pRelayConnector.SendPUUID) + ", ClientId=0x" + Utility.ToHex(pRelayConnector.ClientID));

                SetPhase(PHASE.PHASE_BATTLE_WAIT_CONNECT_RPC, nowTime + WAIT_TIME_CHANGE_PHASE);
            } break;

            case PHASE.PHASE_BATTLE_WAIT_CONNECT_RPC:
            {
                if (m_WaitTime < nowTime)
                {
                    Logger.MLNLOG_ERR("Phase Not Change Phase=" + (UInt32)m_Phase + ", CharaId=0x" + Utility.ToHex(m_CharaId));

                    SetPhase(PHASE.PHASE_BATTLE_END, 0);
                }
            } break;

            case PHASE.PHASE_BATTLE_START:
            {
                SetPhase(PHASE.PHASE_BATTLE, 0);
            } break;

            case PHASE.PHASE_BATTLE:
            {
                // 何もせず、状態が切り替わるのを待つ
            } break;

            case PHASE.PHASE_BATTLE_END:
            {
                ClearPhase();

                m_RpcConnector.RenewRelayConnector();
            } break;
            }

            // RPCのヘルスチェック
            RPC_Update();

            return(0);
        }
Esempio n. 7
0
        public override void Update()
        {
            base.Update();

            UInt64 nowTime = Utility.GetSecond();

            switch (m_Phase)
            {
            case PHASE.PHASE_NONE: {
                if (null == m_pPU)
                {
                    break;
                }

                RelayConnector pRelayConnector = m_pPU.GetRpcConnector().GetRelayConnector();
                if (null == pRelayConnector)
                {
                    break;
                }

                BTL.PU_Client pRpcClient = m_pPU.GetRpcConnector().GetRpcClient();
                if (null == pRpcClient)
                {
                    break;
                }

#if SELECT_SERVER_WEB_API
                SetPhase(PHASE.PHASE_BATTLE_GET_ROOM_LIST, 0);
#else
                SetPhase(PHASE.PHASE_MATCHING_SELECT_SERVER, 0);
#endif
            } break;

#if !SELECT_SERVER_WEB_API
            case PHASE.PHASE_MATCHING_SELECT_SERVER: {
                // サーバの選択
                if (onSelectServerEvent != null)
                {
                    onSelectServerEvent(nowTime);
                }
            } break;

            // マッチングサーバへ接続
            case PHASE.PHASE_MATCHING_CONNECT_SERVER: {
                m_pPU.GetRpcConnector().ConnectServer(m_pMatchingServerInfo.ipAddr, m_pMatchingServerInfo.port, m_pMatchingServerInfo.puUid);

                SetPhase(PHASE.PHASE_MATCHING_WAIT_CONNECT_SERVER, nowTime + WAIT_TIME_CHANGE_PHASE);
            } break;

            // マッチングサーバ接続待ち
            case PHASE.PHASE_MATCHING_WAIT_CONNECT_SERVER:
            {
                if (m_pPU.GetRpcConnector().GetRelayConnector().IsEndSetup())
                {
                    m_pPU.GetRpcConnector().GetRelayConnector().RegistRequestProcessUnit();

                    SetPhase(PHASE.PHASE_MATCHING_CONNECT_RPC, 0);
                    break;
                }

                if (m_WaitTime < nowTime)
                {
                    Debug.LogError("Error:マッチングサーバへの接続に失敗しました。IPアドレス、ポート番号について御確認ください。");
                    Logger.MLNLOG_ERR("Phase Not Change Phase=" + (UInt32)m_Phase);

                    SetPhase(PHASE.PHASE_BATTLE_EXIT_ROOM, 0);
                }
            } break;

            // マッチングサーバとPRC接続
            case PHASE.PHASE_MATCHING_CONNECT_RPC:
            {
                RelayConnector pRelayConnector = m_pPU.GetRpcConnector().GetRelayConnector();
                if (ProcessUnitManager.INVALID_PUUID == pRelayConnector.SendPUUID)
                {
                    break;
                }

                // マッチングプロセスとRPC接続開始
                UInt64 rpcId = m_pPU.GetRpcConnector().ConnectRpc(BTL.INTFID.MATCHING, m_pPU.GetRpcConnector().GetPUUID(), pRelayConnector.SendPUUID, pRelayConnector.ClientID);
                Logger.MLNLOG_INFO("MatchingPU Connect RPCID=0x" + Utility.ToHex(rpcId) + ", dstPUUID=0x" + Utility.ToHex(m_pPU.GetRpcConnector().GetPUUID()) + ", srcPUUID=0x" + Utility.ToHex(pRelayConnector.SendPUUID) + ", clientId=0x" + Utility.ToHex(pRelayConnector.ClientID));

                SetPhase(PHASE.PHASE_MATCHING_WAIT_CONNECT_RPC, nowTime + WAIT_TIME_CHANGE_PHASE);
            } break;

            // RPC接続待ち
            case PHASE.PHASE_MATCHING_WAIT_CONNECT_RPC:
            {
                if (m_pPU.GetRpcConnector().IsConnectedRpc())
                {
                    Logger.MLNLOG_INFO("Change Entry MatchingRoom");
                    SetPhase(PHASE.PHASE_MATCHING_ENTER_ROOM, 0);
                    break;
                }

                if (m_WaitTime < nowTime)
                {
                    Logger.MLNLOG_ERR("Phase Not Change Phase=" + (UInt32)m_Phase);

                    SetPhase(PHASE.PHASE_BATTLE_EXIT_ROOM, 0);
                }
            } break;

            // マッチングルームへ入室
            case PHASE.PHASE_MATCHING_ENTER_ROOM:
            {
                // ルームの選択
                if (onMatchingEnterRoomEvent != null)
                {
                    onMatchingEnterRoomEvent(nowTime);
                }
            } break;

            // マッチングが成立しているか問い合わせ
            case PHASE.PHASE_MATCHING_CHECK_MATCHING_SUCCESS:
            {
                // 入室したルームにマッチングが成立しているかを問い合わせる
                if (m_pPU.GetRoomId() != 0)
                {
                    // まだバトル予約が完了していないなら、問い合わせ続ける
                    if (BTL.PU_Client.PHASE.PHASE_MATCHING_WAIT_APPOINTMENT == m_pPU.GetPhase())
                    {
                        if (m_WaitTime_MatchingState < nowTime)
                        {
                            m_WaitTime_MatchingState = nowTime + 1;
                            m_pPU.GetInterface_Matching(m_pPU.GetRpcConnector().GetRPCID()).Send_GetMatchingStatus(m_pPU.GetRoomId());
                        }
                    }
                    // バトル予約が完了した
                    else
                    {
                        // 予約成功
                        if (m_pPU.GetBattlePuInfo() != null)
                        {
                            ClientScene.Instance.Log("Appointment Battle Success");
                            Logger.MLNLOG_INFO("Appointment Battle Success");
                            SetPhase(PHASE.PHASE_MATCHING_EXIT_ROOM, nowTime + WAIT_TIME_CHANGE_PHASE);
                        }
                        // 空いているバトルが無く、予約に失敗していたら一旦終了
                        else
                        {
                            ClientScene.Instance.Log("Appointment Battle Failed");
                            Logger.MLNLOG_INFO("Appointment Battle Failed");
                            SetPhase(PHASE.PHASE_BATTLE_EXIT_ROOM, 0);
                        }
                    }
                }
                else if (m_WaitTime < nowTime)
                {
                    Logger.MLNLOG_ERR("Phase Not Change Phase=" + (UInt32)m_Phase);

                    SetPhase(PHASE.PHASE_BATTLE_END, 0);
                }
            } break;

            // マッチングが成立したら、バトルに移る前にマッチングルームから退室する
            case PHASE.PHASE_MATCHING_EXIT_ROOM:
            {
                Logger.MLNLOG_INFO("Exit MatchingRoom");
                // マッチングルーム退室要求を出す
                m_pPU.GetInterface_Matching(m_pPU.GetRpcConnector().GetRPCID()).Send_ExitMatchingRoom(GetCharaId(), m_pPU.GetRoomId());

                SetPhase(PHASE.PHASE_BATTLE_ENTER_ROOM, nowTime + WAIT_TIME_CHANGE_PHASE);
            } break;
#else
            case PHASE.PHASE_BATTLE_GET_ROOM_LIST: {
                if (m_WaitTime < nowTime)
                {
                    m_WaitTime = nowTime + 10;

                    SendRequest_GetRoomList();
                }
            } break;
#endif

            // バトルルーム入室
            case PHASE.PHASE_BATTLE_ENTER_ROOM: {
                if (BTL.PU_Client.PHASE.PHASE_BATTLE == m_pPU.GetPhase())
                {
                    m_pPU.EnterRoom();

                    SetPhase(PHASE.PHASE_BATTLE_START, nowTime + WAIT_TIME_CHANGE_PHASE);
                }
                else if (m_WaitTime < nowTime)
                {
                    Logger.MLNLOG_ERR("Phase Not Change Phase=" + (UInt32)m_Phase);

                    SetPhase(PHASE.PHASE_BATTLE_EXIT_ROOM, 0);
                }
            } break;

            // バトル開始
            case PHASE.PHASE_BATTLE_START: {
                if (onBattleStartEvent != null)
                {
                    onBattleStartEvent(nowTime);
                }
                if (m_pPU.IsBattle())
                {
                    Logger.MLNLOG_INFO("Battle Start");
                    SetPhase(PHASE.PHASE_BATTLE, 0);

                    ClientScene.Instance.Log("Battle Start");
                }
                else if (m_WaitTime < nowTime)
                {
                    Logger.MLNLOG_ERR("Phase Not Change Phase=" + (UInt32)m_Phase);

                    SetPhase(PHASE.PHASE_BATTLE_EXIT_ROOM, 0);
                }
            } break;

            // バトル中
            case PHASE.PHASE_BATTLE: {
                if (m_pPU.IsBattle())
                {
                    // バトル中に行いたい処理をコール
                    if (onBattleEvent != null)
                    {
                        onBattleEvent(nowTime);
                    }
                }
                else
                {
                    SetPhase(PHASE.PHASE_BATTLE_END, 0);
                }
            } break;

            // バトル終了
            case PHASE.PHASE_BATTLE_END: {
                if (onBattleEndEvent != null)
                {
                    onBattleEndEvent(nowTime);
                }
                Logger.MLNLOG_INFO("Battle End");
                SetPhase(PHASE.PHASE_BATTLE_EXIT_ROOM, 0);

                ClientScene.Instance.Log("Battle End");
            } break;

            // バトルルーム退室
            case PHASE.PHASE_BATTLE_EXIT_ROOM: {
                m_pPU.ExitRoom();

                SetPhase(PHASE.PHASE_BATTLE_DISCONNECT, nowTime + WAIT_TIME_PHASE_BATTLE_DISCONNECT);
            } break;

            // バトル切断
            case PHASE.PHASE_BATTLE_DISCONNECT: {
                if (m_WaitTime < nowTime)
                {
                    Logger.MLNLOG_INFO("Battle Disconnect");
                    m_pPU.DisconnectAll();

                    SetPhase(PHASE.PHASE_COOL_DOWN, nowTime + WAIT_TIME_PHASE_COOL_DOWN);
                }
            } break;

            case PHASE.PHASE_COOL_DOWN: {
                if (m_WaitTime < nowTime)
                {
                    ClearPhase();

                    m_pPU.GetRpcConnector().RenewRelayConnector();
                    m_pPU.ClearPhase();
                }
            } break;
            }

#if SELECT_SERVER_WEB_API
            m_WebApiManager.Update();
#endif
        }
Esempio n. 8
0
 private void RemoveConnector(RelayConnector connector)
 => _connectors.Remove(connector.Key);
Esempio n. 9
0
        public void DeleteRelayConnector()
        {
            if ( null == this.m_pRelayConnector ) return;

            if ( null != m_pRpcClient ){
            m_pRpcClient.DeleteConnectionBySrcPUUID( m_pRelayConnector.SendPUUID );
            }

            if ( null != m_pProcessUnitBank ){
            m_pProcessUnitBank.RemoveProcessUnitReal( m_PUUID );
            }

            if ( null != m_pSocketManager ){
            UInt32 socketId = this.m_pRelayConnector.SocketID;
            BaseSocket pSocket = m_pSocketManager.GetSocketFromID(socketId);
            if ( null != pSocket ){
                m_pSocketManager.DeleteSocket( pSocket );
                pSocket = null;
            }
            }

            m_pProcessUnit.UnsetRelayConnector( this.m_pRelayConnector );

            this.m_pRelayConnector.SetProcessUnit( null );
            this.m_pRelayConnector.SetSocketManager( null );
            m_pRelayConnector = null;
        }
Esempio n. 10
0
        void Start()
        {
            m_pRelayConnector = null;
            m_pSocketManager = null;
            m_pProcessUnit = null;
            m_pProcessUnitBank = null;

            m_PUUID = 0;
            m_RPCID = 0;
        }
Esempio n. 11
0
        public void NewRelayConnector()
        {
            if ( null != m_pRelayConnector ) return;

            m_pRelayConnector = new RelayConnector( true );
            m_pRelayConnector.SetSocketManager( m_pSocketManager );
            m_pRelayConnector.SetProcessUnit( m_pProcessUnit );
        }