Exemplo n.º 1
0
        /// <summary>
        /// 广播给一个房间内的一个玩家
        /// </summary>
        /// <param name="room"></param>
        /// <param name="opCode"></param>
        /// <param name="subCode"></param>
        /// <param name="value"></param>
        /// <param name="exClient"></param>
        private void singleBrocast(FightRoom room, int opCode, int subCode, object value, int userId, ClientPeer exClient = null)
        {
            SocketMsg msg = new SocketMsg();

            msg.OpCode  = opCode;
            msg.SubCode = subCode;
            msg.Value   = value;
            byte[] data   = EncodeTool.EncodeMsg(msg);
            byte[] packet = EncodeTool.EncodePacket(data);
            foreach (var player in room.PlayerList)
            {
                if (userCache.IsOnline(player.UserId))
                {
                    ClientPeer client = userCache.GetClientPeer(player.UserId);
                    if (player.UserId == userId)
                    {
                        if (client == exClient)
                        {
                            continue;
                        }
                        client.Send(packet);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 优化网络消息
        /// </summary>
        /// <param name="opCode"></param>
        /// <param name="subCode"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private byte[] GetMsg(int opCode, int subCode, object value)
        {
            MessageData msg = new MessageData(opCode, subCode, value);

            byte[] msgBytes  = EncodeTool.EncodeMsg(msg);
            byte[] msgPacket = EncodeTool.EncodeMessage(msgBytes);
            return(msgPacket);
        }
Exemplo n.º 3
0
 public void SendMsg(NetMsg msg)
 {
     try {
         byte[] data   = EncodeTool.EncodeMsg(msg);
         byte[] packet = EncodeTool.EncodePacket(data);
         clientSocket.Send(packet);
     }
     catch (Exception e) {
         Debug.LogError(e.Message);
     }
 }
Exemplo n.º 4
0
    public void Send(SocketMsg msg)
    {
        byte[] data   = EncodeTool.EncodeMsg(msg);
        byte[] packet = EncodeTool.EncodePacket(data);

        try
        {
            socket.Send(packet);
        }
        catch (Exception e)
        {
            Debug.Log(e.Message);
        }
    }
Exemplo n.º 5
0
    public void Send(int opCode, int subCode, object value)
    {
        SocketMsg msg = new SocketMsg(opCode, subCode, value);

        byte[] packet = EncodeTool.EncodeMessage((EncodeTool.EncodeMsg(msg)));
        try
        {
            socket.Send(packet);
        }
        catch (Exception e)
        {
            Debug.Log(e.ToString());
        }
    }
Exemplo n.º 6
0
        /// <summary>
        /// 广播发消息,给除自己以外的客户端发消息
        /// </summary>
        public void Broadcast(int opCode, int subCode, object value, ClientPeer exceptClient = null)
        {
            NetMsg msg = new NetMsg(opCode, subCode, value);

            byte[] data   = EncodeTool.EncodeMsg(msg);
            byte[] packet = EncodeTool.EncodePacket(data);
            foreach (var client in clientList)
            {
                if (client == exceptClient)
                {
                    continue;
                }
                client.SendMsg(packet);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 广播房间内的所有玩家信息
        /// </summary>
        public void Brocast(int opCode, int subCode, object value, ClientPeer exclient = null)
        {
            SocketMsg msg = new SocketMsg();

            msg.OpCode  = opCode;
            msg.SubCode = subCode;
            msg.Value   = value;
            byte[] data   = EncodeTool.EncodeMsg(msg);
            byte[] packet = EncodeTool.EncodePacket(data);
            foreach (var player in PlayerList)
            {
                ClientPeer client = userCache.GetClientPeer(player.UserId);
                client.Send(packet);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 广播发消息,给除自己以外的客户端发消息
        /// </summary>
        public void Broadcast(int opCode, int subCode, object value, ClientPeer exceptClient = null)
        {
            NetMsg msg = new NetMsg(opCode, subCode, value);

            byte[] data   = EncodeTool.EncodeMsg(msg);
            byte[] packet = EncodeTool.EncodePacket(data);
            foreach (var player in playerList)
            {
                ClientPeer client = DatabaseManager.GetClientPeerByUserId(player.id);
                if (client == exceptClient)
                {
                    continue;
                }
                client.SendMsg(packet);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// broadcast to all palyer in room
        /// </summary>
        /// <param name="opCode"></param>
        /// <param name="subCode"></param>
        /// <param name="value"></param>
        /// <param name="exClient"></param>
        public void Broadcast(int opCode, int subCode, object value, ClientPeer currentClient = null)
        {
            SocketMessage msg = new SocketMessage(opCode, subCode, value);

            byte[] data   = EncodeTool.EncodeMsg(msg);
            byte[] packet = EncodeTool.EncodePacket(data);

            foreach (var client in UserIdClientDict.Values)
            {
                if (client == currentClient)
                {
                    continue;
                }
                client.Send(packet);
            }
        }
Exemplo n.º 10
0
    public void Send(int opCode, int subCode, object value)
    {
        SocketMsg msg = new SocketMsg(opCode, subCode, value);

        byte[] data   = EncodeTool.EncodeMsg(msg);
        byte[] packet = EncodeTool.EncodePacket(data);

        try
        {
            socket.Send(packet);
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
        }
    }
Exemplo n.º 11
0
        /// <summary>
        /// 向房间内玩家广播消息
        /// </summary>
        /// <param name="opCode"></param>
        /// <param name="fightCode"></param>
        /// <param name="value"></param>
        /// <param name="clientPeer"></param>
        public void Brocast(FightRoomModel fightRoom, int opCode, int fightCode, object value, ClientPeer exClientPeer = null)
        {
            SocketMsg socketMsg = new SocketMsg(opCode, fightCode, value);

            byte[] vs     = EncodeTool.EncodeMsg(socketMsg);
            byte[] packet = EncodeTool.EncodeMessage(vs);
            foreach (var player in fightRoom.PlayerDtos)
            {
                UserModel    userModel    = userModelCache.GetModelByUid(player.Uid);
                AccountModel accountModel = accountCache.GetModel(userModel.Aid);
                ClientPeer   clientPeer   = accountCache.GetClientPeerByAcc(accountModel.acc);
                if (clientPeer != exClientPeer)
                {
                    clientPeer.Send(packet);
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 广播房间内的所有玩家信息
        /// </summary>
        public void Brocast(int opCode, int subCode, object value, ClientPeer exClient = null)
        {
            SocketMsg msg = new SocketMsg();

            msg.OpCode  = opCode;
            msg.SubCode = subCode;
            msg.Value   = value;
            byte[] data   = EncodeTool.EncodeMsg(msg);
            byte[] packet = EncodeTool.EncodePacket(data);
            foreach (var client in UIdClientDict.Values)
            {
                if (client == exClient)
                {
                    continue;
                }
                client.Send(packet);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// 广播发消息
        /// </summary>
        public void Broadcase(int opCode, int subCode, object value, ClientPeer exceptClient = null)
        {
            Console.WriteLine("--广播有玩家加入的消息--" + opCode + subCode);
            NetMsg msg = new NetMsg(opCode, subCode, value);

            byte[] data   = EncodeTool.EncodeMsg(msg);
            byte[] packet = EncodeTool.EncodePacket(data);
            foreach (var client in clientList)
            {
                if (client == exceptClient)
                {
                    Console.WriteLine("--wangzhi--房间里玩家的id--" + client.Id);
                    Console.WriteLine("--wangzhi--忽略的玩家ID--" + exceptClient.Id);
                    continue;
                }

                client.SendMsg(packet);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// 广播
        /// </summary>
        /// <param name="opCode"></param>
        /// <param name="subCode"></param>
        /// <param name="value"></param>
        /// <param name="clientPeer"></param>
        public void Brocast(FightRoom room, int opCode, int subCode, object value, ClientPeer exClient = null)
        {
            SocketMessage msg = new SocketMessage(opCode, subCode, value);

            byte[] data   = EncodeTool.EncodeMsg(msg);
            byte[] packet = EncodeTool.EncodePacket(data);

            foreach (var player in room.PlayerList)
            {
                if (userCache.IsOnline(player.UserId))
                {
                    ClientPeer client = userCache.GetClientPeer(player.UserId);
                    if (client == exClient)
                    {
                        continue;
                    }
                    client.Send(packet);
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// 广播
        /// </summary>
        /// <param name="opCode"></param>
        /// <param name="subCode"></param>
        /// <param name="value"></param>
        /// <param name="exClient"></param>
        private void brocast(_21MutiFightRoom room, int opCode, int subCode, object value, ClientPeer exClient = null)
        {
            SocketMsg msg = new SocketMsg(opCode, subCode, value);

            byte[] data   = EncodeTool.EncodeMsg(msg);
            byte[] packet = EncodeTool.EncodePacket(data);

            foreach (var player in room.PlayerList)
            {
                //fixbug923
                if (player != null && userCache.IsOnline(player.UserId) && !room.LeaveUIdList.Contains(player.UserId))
                {
                    ClientPeer client = userCache.GetClientPeer(player.UserId);
                    if (client == exClient)
                    {
                        continue;
                    }
                    client.Send(packet);
                }
            }
        }