Example #1
0
        public AChannel GetChannel(NetChannelType channelType)
        {
            AChannel channel;

            this.channels.TryGetValue(channelType, out channel);
            return(channel);
        }
Example #2
0
        public bool BeginConnect(NetChannelType channel, string ip, int port, Action <bool, NetChannelType> callback = null)
        {
            NetChannel netChannel = GetChannel(channel);

            if (netChannel == null)
            {
                return(false);
            }
            return(netChannel.BeginConnect(ip, port, callback));
        }
Example #3
0
        public static void SendOOBPacket(NetChannelType type, NetAddress address, string format, params object[] others)
        {
            string message = "????" + string.Format(format, others);

            byte[] data = Encoding.UTF8.GetBytes(message);

            data[0] = 0xFF; data[1] = 0xFF; data[2] = 0xFF; data[3] = 0xFF;

            SendPacket(type, address, data);
        }
Example #4
0
        public bool RunFrameData(NetChannelType channel, int frameIndex)
        {
            NetChannel netChannel = GetChannel(channel);

            if (netChannel == null)
            {
                return(false);
            }
            return(netChannel.RunFrameData(frameIndex));
        }
Example #5
0
        public void DisConnect(NetChannelType channel)
        {
            NetChannel netChannel = GetChannel(channel);

            if (netChannel == null)
            {
                return;
            }
            netChannel.DisConnect();
        }
Example #6
0
        public bool IsChannelConnected(NetChannelType channelType)
        {
            AChannel channel = GetChannel(channelType);

            if (channel == null)
            {
                return(false);
            }
            return(true);
        }
Example #7
0
 public NetChannel(NetChannelType type, SocketClient socketClient)
 {
     m_eChannelType  = type;
     m_queueRecvData = new Queue <NetRecvData>();
     m_cSocketClient = socketClient;
     m_cSocketClient.OnDisConnect += OnDisConnect;
     m_dicServerMsg   = new Dictionary <short, List <IServerMsg> >();
     m_cMsgDispatcher = new EDynamicDispatcher();
     m_cFrameData     = new NetFrameData();
     LoadNetMessageEvent();
 }
Example #8
0
 private static void SendLoopbackPacket(NetChannelType type, byte[] packet)
 {
     if (type == NetChannelType.ClientToServer)
     {
         _serverLoopQueue.Enqueue(packet);
     }
     else if (type == NetChannelType.ServerToClient)
     {
         _clientLoopQueue.Enqueue(packet);
     }
 }
Example #9
0
        public void Close(NetChannelType channelType)
        {
            AChannel channel = this.GetChannel(channelType);

            if (channel == null || channel.Id == 0)
            {
                return;
            }
            this.channels.Remove(channelType);
            channel.Dispose();
        }
Example #10
0
 public void RemoveMsgCallback(NetChannelType channel, short receiveOpcode, MsgCallback callback)
 {
     if (callback != null)
     {
         NetChannel netChannel = GetChannel(channel);
         if (netChannel == null)
         {
             return;
         }
         netChannel.RemoveMsgCallback(receiveOpcode, callback);
     }
 }
Example #11
0
 public void AddMsgCallback(NetChannelType channel, short receiveOpcode, MsgCallback callback, bool once = false)
 {
     if (callback != null)
     {
         NetChannel netChannel = GetChannel(channel);
         if (netChannel == null)
         {
             return;
         }
         netChannel.AddMsgCallback(receiveOpcode, callback, once);
     }
 }
Example #12
0
        //不监听回复消息
        public void SendMsg(NetChannelType channel, short sendOpcode, object data)
        {
            NetSendData sendData;

            sendData.sendOpcode = sendOpcode;
            sendData.data       = data;
            NetChannel netChannel = GetChannel(channel);

            if (netChannel == null)
            {
                return;
            }
            netChannel.SendMsg(sendData);
        }
 private void OnConnect(bool succ, NetChannelType channel)
 {
     if (channel == NetChannelType.Game)
     {
         if (succ)
         {
             CLog.Log("连接战斗服务器成功");
             FrameSyncSys.Instance.StartRun();//开始帧同步
             this.OnExecuteDone(CmdExecuteState.Success);
         }
         else
         {
             CLog.LogError("连接战斗服务器失败");
             this.OnExecuteDone(CmdExecuteState.Fail);
         }
     }
 }
Example #14
0
 public static void SendPacket(NetChannelType type, NetAddress address, byte[] packet)
 {
     if (address.Type == AddressType.Loopback)
     {
         SendLoopbackPacket(type, packet);
     }
     else
     {
         if (net_forceLatency.GetValue <int>() == 0)
         {
             SendPacketInternal(address, packet);
         }
         else
         {
             _sendQueue.Add(new NetPacket(address, packet));
         }
     }
 }
Example #15
0
        public void CreateChannel(NetChannelType channel, NetChannelModeType channelMode)
        {
            var curChannel = GetChannel(channel);

            if (curChannel != null)
            {
                curChannel.DisConnect();
            }
            curChannel = null;
            switch (channelMode)
            {
            case NetChannelModeType.Tcp:
                curChannel = new NetChannel(channel, new TCPSocketClient());
                break;

            case NetChannelModeType.StandAlone:
                curChannel = new NetChannel(channel, new StandAloneSocketClient());
                break;
            }
            m_arrChannel[(int)channel] = curChannel;
        }
Example #16
0
        public static byte[] GetLoopbackPacket(NetChannelType type)
        {
            Queue <byte[]> queue = null;

            if (type == NetChannelType.ClientToServer)
            {
                queue = _serverLoopQueue;
            }
            else if (type == NetChannelType.ServerToClient)
            {
                queue = _clientLoopQueue;
            }

            if (queue != null)
            {
                if (queue.Count > 0)
                {
                    return(queue.Dequeue());
                }
            }

            return(null);
        }
Example #17
0
 public NetChannel(NetChannelType type, NetAddress address)
 {
     ChannelType = type;
     Address     = address;
 }
Example #18
0
 private void OnCallback(bool succ, NetChannelType channel)
 {
     CLog.Log("返回连接服务器结果:" + succ);
 }
Example #19
0
        /// <summary>
        /// Creates info from a net request
        /// </summary>
        /// <param name="fromReq"></param>
        public AssetRequestInfo(TransferRequestPacket fromReq, IClientAPI userInfo)
        {
            _origin = RequestOrigin.SRC_NET;
            _netSrc = (NetSourceType)fromReq.TransferInfo.SourceType;
            _netChannel = (NetChannelType)fromReq.TransferInfo.ChannelType;

            if (fromReq.TransferInfo.SourceType == 2)
            {
                //direct asset request
                _requestedId = new UUID(fromReq.TransferInfo.Params, 0);
            }
            else if (fromReq.TransferInfo.SourceType == 3)
            {
                //inventory asset request
                _requestedId = new UUID(fromReq.TransferInfo.Params, 80);
            }
            else if (fromReq.TransferInfo.SourceType == 4)
            {
                //sim estate request
                //We have to just send the covenent in this case,
                // I've looked through the params, and the UUID
                // of the covenent isn't in there (Matt Beardmore)
                _requestedId = userInfo.Scene.RegionInfo.RegionSettings.Covenant;
            }

            _transferId = fromReq.TransferInfo.TransferID;
            _params = fromReq.TransferInfo.Params;
        }
Example #20
0
 protected NetChannel GetChannel(NetChannelType type)
 {
     return(m_arrChannel[(int)type]);
 }
Example #21
0
 //监听回复消息
 public void SendMsg(NetChannelType channel, short sendOpcode, short receiveOpcode, object data, MsgCallback callback)
 {
     AddMsgCallback(channel, receiveOpcode, callback, true);
     SendMsg(channel, sendOpcode, data);
 }
Example #22
0
        public void Connect(NetChannelType channelType, string host, int port)
        {
            AChannel channel = Share.Scene.GetComponent <NetworkComponent>().ConnectChannel(host, port);

            this.channels[channelType] = channel;
        }