/// <summary>
 /// Creates a new <see cref="NetClientReceiver"/> instance.
 /// </summary>
 /// <param name="client">Client.</param>
 public NetClientReceiver(INetClient client)
     : base(client.PacketProcessor)
 {
     this._client                      = client;
     this._socketAsyncEvent            = new SocketAsyncEventArgs();
     this._socketAsyncEvent.Completed += this.OnCompleted;
 }
        public LidgrenClientNetworkSession(INetClient netClient, ILoggerFactory loggerFactory)
        {
            _netClient = netClient;
            _logger = loggerFactory.GetLogger(this.GetType());

            ClientDisconnected += (obj, args) => _logger.Info("ZAK HERE: Client disconnected");
        }
示例#3
0
 public RPCEvent(INetClient client, NetworkEvent netEvent, BSONObject bson, String methodName)
 {
     this._client     = client;
     this._netEvent   = netEvent;
     this._bson       = bson;
     this._methodName = methodName;
 }
示例#4
0
        /// <summary>
        ///     Fills the settings.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="property">The property.</param>
        public void Configure(INetClient client, PropertyInfo property)
        {
            if (BaseUri == null)
            {
                BaseUri = property.GetCustomAttributes <BaseUriAttribute>(true)?.FirstOrDefault()?.BaseUri;
            }

            if (BaseUri == null)
            {
                BaseUri = client.GetType().GetCustomAttributes <BaseUriAttribute>(true)?.FirstOrDefault()?.BaseUri;
            }

            if (SerializerSettings == null)
            {
                SerializerSettings = property.GetCustomAttributes <SerializerSettingsAttribute>(true)?.FirstOrDefault()?.SerializerSettings;
            }

            if (SerializerSettings == null)
            {
                SerializerSettings = client.GetType().GetCustomAttributes <SerializerSettingsAttribute>(true)?.FirstOrDefault()?.SerializerSettings;
            }

            var routes = property.GetCustomAttributes <RouteAttribute>(true)?.Select(attribute => attribute.Route);

            if (routes != null)
            {
                foreach (var route in routes)
                {
                    Routes.Add(route);
                }
            }
        }
示例#5
0
        public void ReceiveEvent(INetClient client, NetworkEvent netEvent, BSONObject bson)
        {
            switch (netEvent)
            {
            case NetworkEvent.ClientUpdate:
                if (!createFromNetworkEvent(client, netEvent, bson).isCanceled)
                {
                    NetObjectManager.Obj.UpdateObjects(bson);
                }
                break;

            case NetworkEvent.RPC:
                if (!createEventFromNetworkRPCEvent(client, netEvent, bson).isCanceled)
                {
                    RPCManager.HandleReceiveRPC(client, bson);
                }
                break;

            case NetworkEvent.RPCResponse:
                if (!createFromNetworkResponseEvent(client, netEvent, bson).isCanceled)
                {
                    RPCManager.HandleQueryResponse(bson);
                }

                break;
            }
        }
    public IEnumerator AsyncGet(string url, INetClient client, TokenData token)
    {
        UnityWebRequest www;

        using (www = UnityWebRequest.Get(url))
        {
            www.SetRequestHeader("AUTHORIZATION", token.token_type + " " + token.access_token);

            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                client.Break();
                Debug.Log(www.error);
                StatusConnection = "network connection: wait";
            }
            else
            {
                StatusConnection = "network connection: established";

                while (!www.isDone)
                {
                    isDownloaded = false;
                    yield return(new WaitForSeconds(0.5f));
                }

                body = www.downloadHandler.text;

                client.GetResult(body);
            }
        }
    }
        public static void Prefix(Player player, INetClient client)
        {
            PlayerLoginEvent cEvent = new PlayerLoginEvent(player, client);
            IEvent           iEvent = cEvent;

            EventManager.CallEvent(ref iEvent);
        }
示例#8
0
    public bool Connect(bool bTCP, string ip, ushort port, uint newip = 0, ushort newport = 0)
    {
        if (m_TCPClient != null && m_TCPClient.IsConnected)
        {
            LogMgr.Log("TCP is connected.");
            return(false);
        }
        INetClient tt;
        //bTCP = true;
        bool bret;

        if (bTCP)
        {
            tt   = new TCPClient(this);
            bret = tt.Connect(ip, port, newip, newport);
        }
        else
        {
            tt   = new UDPClient(this);
            bret = tt.Connect(ip, port, newip, newport);
        }

        m_TCPClient = tt;
        return(bret);
    }
示例#9
0
 public PeerForP2PBase(object peer, object publicIP, INetClient client, bool NAT)
 {
     socket      = peer;
     PublicIP    = publicIP;
     this.client = client;
     this.NAT    = NAT;
 }
示例#10
0
        public bool Connect(bool bTcp, string ip, ushort port, uint newip = 0, ushort newport = 0)
        {
            Debug.Log("连接到服务器 IP = " + ip);
            if (tCPClient != null && tCPClient.IsConnected)
            {
                Debug.Log("TCP is connected.");
                return(false);
            }
            INetClient tt;
            bool       bret = true;

            if (bTcp)
            {
                tt   = new TCPClient(this);
                bret = tt.Connect(ip, port);
            }
            else
            {
                tt   = new UDPClient(this);
                bret = tt.Connect(ip, port);
                //tt = new UDPClient(this);
                //bret = tt.Connect(ip, port, newip, newport);
            }

            tCPClient = tt;
            return(bret);
        }
示例#11
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Resource{T}" /> class.
 /// </summary>
 /// <param name="client">The client.</param>
 /// <param name="settings">The settings.</param>
 /// <param name="onError">The on error.</param>
 /// <param name="expression">The expression.</param>
 public Resource(INetClient client, ResourceSettings settings, Action <Exception> onError, Expression expression)
 {
     Client     = client;
     Settings   = settings;
     Provider   = new RestQueryProvider <T>(this);
     OnError    = onError;
     Expression = expression ?? Expression.Constant(this);
 }
示例#12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Command{T}" /> class.
 /// </summary>
 /// <param name="client">The client.</param>
 /// <param name="property">The property.</param>
 /// <param name="onError">The on error.</param>
 /// <param name="expression">The expression.</param>
 public Command(INetClient client, PropertyInfo property, Action <Exception> onError, Expression expression)
 {
     Client   = client;
     Property = property;
     /////////////////////////////////////////////////////////////////Provider = new JsonRpcQueryProvider<T>(this);
     OnError    = onError;
     Expression = expression ?? Expression.Constant(this);
 }
示例#13
0
 public void Disconnect()
 {
     if (m_TCPClient != null)
     {
         m_TCPClient.Disconnect();
         m_TCPClient = null;
     }
 }
示例#14
0
        public async void ConnectToServer()
        {
            INetClient client = await this.ConnectClient();

            Assert.Equal(true, client.IsConnected);

            client.Disconnect();
        }
示例#15
0
 public void Disconnect()
 {
     if (tCPClient != null)
     {
         tCPClient.Disconnect();
         tCPClient = null;
     }
 }
示例#16
0
        public static void SendShutdownServer(INetClient client)
        {
            using (var packet = new NetPacket())
            {
                packet.Write((ushort)OpCode.Shutdown);

                client.Send(packet);
            }
        }
示例#17
0
 public FlightSimPlayer(INetClient netClient, IFileIterator fileIterator)
 {
     this.netClient    = netClient;
     this.fileIterator = fileIterator;
     // call these functions everytime new data is read
     fileIterator.OnLineChanged += SendCurrentFrame;
     fileIterator.OnLineChanged += UpdateTimerString;
     fileIterator.OnLineChanged += Sleep;
 }
示例#18
0
        public static void AddClientEventHandler(string clientName, SocketEventHandler socketEventHandler)
        {
            INetClient client = GetClient(clientName);

            if (client != null)
            {
                client.OnSocketEvent += socketEventHandler;
            }
        }
示例#19
0
 /// <summary>
 /// Creates a new <see cref="NetClientConnector"/> instance.
 /// </summary>
 public NetClientConnector(INetClient client)
 {
     this._client           = client;
     this._socketAsyncEvent = new SocketAsyncEventArgs
     {
         DisconnectReuseSocket = true
     };
     this._socketAsyncEvent.Completed += this.OnCompleted;
 }
 /// <summary>
 /// Creates a new <see cref="NetClientReceiver"/> instance.
 /// </summary>
 /// <param name="client">Client.</param>
 /// <param name="onReceiveServerDisconnect"></param>
 /// <param name="onReceiveSocketError"></param>
 public GarlicNetClientReceiver(INetClient client, EventHandler onReceiveServerDisconnect, EventHandler <SocketError> onReceiveSocketError)
     : base(client.PacketProcessor)
 {
     _client                      = client;
     _socketAsyncEvent            = new SocketAsyncEventArgs();
     _socketAsyncEvent.Completed += OnCompleted;
     _onReceiveServerDisconnect   = onReceiveServerDisconnect;
     _onReceiveSocketError        = onReceiveSocketError;
 }
示例#21
0
        public static void SendStopScriptDomain(INetClient client)
        {
            using (var packet = new NetPacket())
            {
                packet.Write((ushort)OpCode.StopScriptDomain);

                client.Send(packet);
                Thread.Sleep(1000);
            }
        }
示例#22
0
        /// <summary>
        /// Sends a request to change the name of the client.
        /// </summary>
        /// <param name="client">Current client.</param>
        /// <param name="name">New client name.</param>
        public static void SetName(INetClient client, string name)
        {
            using (INetPacketStream packet = new NetPacket())
            {
                packet.Write <byte>((byte)ChatPacketType.SetName);
                packet.Write <string>(name);

                client.Send(packet);
            }
        }
示例#23
0
        /// <summary>
        /// Sends a chat message.
        /// </summary>
        /// <param name="client">Current client.</param>
        /// <param name="message">Message to send.</param>
        public static void SendChatMessage(INetClient client, string message)
        {
            using (INetPacketStream packet = new NetPacket())
            {
                packet.Write <byte>((byte)ChatPacketType.Chat);
                packet.Write <string>(message);

                client.Send(packet);
            }
        }
示例#24
0
        public static void SendWorkingDirectory(INetClient client, string workingDirectory)
        {
            using (var packet = new NetPacket())
            {
                packet.Write((ushort)OpCode.SetWorkingDirectory);
                packet.Write(workingDirectory);

                client.Send(packet);
                Thread.Sleep(1000);
            }
        }
示例#25
0
        public static void DestroyClient(string name)
        {
            INetClient client = GetClient(name);

            if (client == null)
            {
                return;
            }
            client.Dispose();
            CLIENTS.Remove(name);
        }
示例#26
0
文件: Client.cs 项目: AyyTee/Aventyr
        public Client(IPEndPoint serverAddress, IController controller, INetClient client)
        {
            _controller = controller;

            _client = client;
            _client.Start();

            _client.Connect(serverAddress);

            Scene = new Scene();
            Scene.Gravity = new Vector2();
        }
示例#27
0
        public async void SendPacketToServer()
        {
            INetClient client = await this.ConnectClient();

            if (!client.IsConnected)
            {
                throw new EtherDisconnectedException();
            }

            // TODO Send packet and wait for answer

            client.Disconnect();
        }
示例#28
0
 public ClientApi(
     IClientManager clientManager,
     IClientCommandManager commandManager,
     IUiManager uiManager,
     INetClient netClient,
     IEventAggregator eventAggregator
     )
 {
     ClientManager   = clientManager;
     CommandManager  = commandManager;
     UiManager       = uiManager;
     NetClient       = netClient;
     EventAggregator = eventAggregator;
 }
示例#29
0
        public static void SendAuthentication(INetClient client, WorldConfiguration worldConfiguration)
        {
            using (var packet = new NetPacket())
            {
                packet.Write((uint)ISCPacketType.AUTHENT);
                packet.Write(worldConfiguration.Id);
                packet.Write(worldConfiguration.Host);
                packet.Write(worldConfiguration.Name);
                packet.Write((byte)ISCServerType.World);
                packet.Write(worldConfiguration.ClusterId);

                // TODO: add more information to packet if needed.
                client.Send(packet);
            }
        }
示例#30
0
        public ClientLinker(ClientListen listen, ProtocolType protocolType, bool enableP2P)
        {
            listener = listen;
            type     = protocolType;
            switch (type)
            {
            case ProtocolType.Tcp:
            {
                client = new NetClientTCP(enableP2P);
                break;
            }

            case ProtocolType.Udp:
            {
                client = new NetClientUDP(enableP2P);
                break;
            }
            }
        }
示例#31
0
        // Initialize Objects and add notify events
        private FlightModel()
        {
            netClient       = new FlightNetClient();
            fileIterator    = new FlightDataIterator();
            dataParser      = new XMLParser();
            dataAnalyzer    = new DataAnalyzer();
            libLoader       = new LibraryLoader();
            anomalyAnalyzer = new AnomalyAnalyzer(libLoader);
            selectedPlot    = new MonitorGraph(dataAnalyzer, fileIterator);
            correlatedPlot  = new MonitorGraph(dataAnalyzer, fileIterator);
            anomalyPlot     = new AnomalyGraph(dataAnalyzer, fileIterator, anomalyAnalyzer);
            simPlayer       = new FlightSimPlayer(netClient, fileIterator);
            joystick        = new FlightJoystick(fileIterator, dataAnalyzer);
            dashboard       = new FlightDashboard(fileIterator, dataAnalyzer);

            // add notify events
            simPlayer.PropertyChanged += PropertyChangedFunction;
            joystick.PropertyChanged  += PropertyChangedFunction;
            dashboard.PropertyChanged += PropertyChangedFunction;
        }
示例#32
0
        private Event.Event createEventFromNetworkRPCEvent(INetClient client, NetworkEvent netEvent, BSONObject bson)
        {
            BSONValue value;

            bson.TryGetValue("method", out value);
            string methodname = value.StringValue;

            switch (methodname)
            {
            case "KeepAlive":
                return(FireEventTool.call(new KeepAliveEvent(client, netEvent, bson, methodname)));

            case "PlayerInteract":
                return(FireEventTool.call(new PlayerInteract(client, netEvent, bson, methodname)));

            default:
                return(FireEventTool.call(new NotregistredRPCMethodEvent(client, netEvent, bson, methodname)));
            }

            return(null);
        }
 public void SetUp()
 {
     stubNetClient = MockRepository.GenerateStub<INetClient>();
     clientNetworkSession = new LidgrenClientNetworkSession(stubNetClient, DummyLogger.Factory);
 }