コード例 #1
0
        /// <summary>
        /// 玩家上线的处理
        /// </summary>
        /// <param name="client"></param>
        private void OnPlayerOnline(MOBAClient client)
        {
            int accountID = accountCache.GetID(client);
            int playerID  = playerCache.GetID(accountID);

            //防止重复在线
            if (playerCache.IsOnLine(client))
            {
                return;
            }
            //上线
            playerCache.OnLine(client, playerID);
            //上线的时候,通知在线好友,显示在线状态
            PlayerModel playerModel = playerCache.GetPlayerModel(playerID);

            if (playerModel != null)
            {
                foreach (int friendID in playerModel.FriendIdList)
                {
                    if (!playerCache.IsOnLine(friendID))    //因为GetPlayerModel,GetClient是获取在线玩家的数据
                    {
                        continue;
                    }
                    MOBAClient friendClient = playerCache.GetClient(friendID);
                    Send(friendClient, OperationCode.PlayerCode, OpPlayer.FriendOnlineState, 0, "好友玩家上线", playerModel.Id);
                }
            }
            PlayerDto playerDto = ToDto(playerCache.GetPlayerModel(playerID));

            //发送
            Send(client, OperationCode.PlayerCode, OpPlayer.Online, 0, "上线成功", JsonMapper.ToJson(playerDto));
        }
コード例 #2
0
        /// <summary>
        /// 上线
        /// </summary>
        /// <param name="client"></param>
        private void OnLine(MobaClient client)
        {
            int accId    = accountCache.GetId(client);
            int playerId = playerCache.GetId(accId);

            //防止重复在线
            if (playerCache.IsOnLine(client))
            {
                return;
            }
            //上线
            playerCache.OnLine(client, playerId);

            //每次上线的时候要通知好友显示上线状态
            PlayerModel myModel = playerCache.GetModel(client);

            if (myModel != null)
            {
                string[] friends = myModel.FriendIdList.Split(',');
                foreach (string item in friends)
                {
                    if (item.Equals(""))
                    {
                        continue;
                    }
                    int itemId = int.Parse(item);
                    if (!playerCache.IsOnLine(itemId))
                    {
                        continue;
                    }
                    MobaClient tempClient = playerCache.GetClient(itemId);
                    Send(tempClient, OpCode.PlayerCode, OpPlayer.FriendOnLine, 0, "此玩家上线", myModel.Id);
                }
            }

            PlayerModel model = playerCache.GetModel(playerId);
            PlayerDto   dto   = ToDto(model);

            Send(client, OpCode.PlayerCode, OpPlayer.OnLine, 0, "角色上线成功", JsonMapper.ToJson(dto));
        }