Esempio n. 1
0
        private void OnChat(MOBAClient client, string text)
        {
            //给当前客户端所在的房间内的所有人发一条消息
            PlayerModel playerModel = playerCache.GetPlayerModel(client);

            if (playerModel == null)
            {
                return;
            }
            SelectRoom selectRoom = selectCache.GetRoom(playerModel.Id);

            if (selectRoom != null)
            {
                string str = string.Format("{0}:{1}", playerModel.Name, text);
                selectRoom.Broadcast(OperationCode.SelectCode, OpSelect.Chat, 0, "有玩家发言了", null, str);
            }
        }
Esempio n. 2
0
        public void OnDisConnect(MOBAClient client)
        {
            //下线的时候,通知在线好友,显示离线状态
            //***这里要通过客户端获取到玩家账号ID,再用账号ID获取到玩家ID,否则会报空
            int accountID = accountCache.GetID(client);
            int playerID  = playerCache.GetID(accountID);

            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, 1, "好友玩家下线", playerModel.Id);
                }
            }
            matchCache.OffLine(client, playerID);
            playerCache.OffLine(client);
        }