コード例 #1
0
        public void AsyncLoginPlayer(INetworkChannel channel, int messageType, object playerInfoObj)
        {
            IPlayerInfo playerInfo = (IPlayerInfo)playerInfoObj;

            logger.InfoFormat("Received LocalLogin Message ... playerName:{0}", playerInfo.PlayerName);

            if (channelToPlayer.Count == 0 && ContextsWrapper.contexts.player.count == 0)
            {
                ResetContexts(false);
                logger.InfoFormat("Reset All Entity Finish ...");
            }

            if (!channelToPlayer.ContainsKey(channel))
            {
                UpdateTestPlayerInfo(playerInfo);
                // 大厅传入错误RoleModelId
                if (null == SingletonManager.Get <RoleConfigManager>().GetRoleItemById(playerInfo.RoleModelId))
                {
                    logger.Error("RoleModelIdError:  " + playerInfo.RoleModelId);
                    playerInfo.RoleModelId = 2;
                }

                var player = CreateNewPlayerEntity(playerInfo);
                playerInfo.PlayerEntity = player;
                player.ReplaceNetwork(channel);

                playerInfo.StatisticsData = player.statisticsData.Statistics;
                if (ContextsWrapper.FreeArgs.Rule.GameStartTime > 0)
                {
                    playerInfo.StatisticsData.GameJoinTime =
                        ContextsWrapper.FreeArgs.Rule.ServerTime;
                }

                channelToPlayer[channel] = player;
                channel.MessageReceived += ChannelOnMessageReceived;
                channel.Disconnected    += ChannelOnDisonnected;


                if (!player.hasUpdateMessagePool)
                {
                    player.AddUpdateMessagePool();
                }
                player.updateMessagePool.LastestExecuteUserCmdSeq = -1;

                playerInfo.InitPosition = player.position.Value;

                NoticeHallPlayerLoginSucc(player);
                player.ReplaceStage(EPlayerLoginStage.CreateEntity);
                var msg = PlayerInfoMessage.Allocate();
                msg.ConvertFrom(playerInfo);
                channel.SendReliable((int)EServer2ClientMessage.PlayerInfo, msg);
                logger.InfoFormat("player login with name {0}, key {1}, game rule {2}, msp id {3}",
                                  playerInfo.PlayerName, player.entityKey, 0, 0);
                msg.ReleaseReference();
            }
            else
            {
                logger.ErrorFormat("player duplicate login from name:{0}, channe:{1}", playerInfo.PlayerName, channel);
            }
        }