Example #1
0
        private void SetStatus(ConnectionStatus status)
        {
            switch (status)
            {
            case ConnectionStatus.Connecting:

                if (Status != ConnectionStatus.Connecting)
                {
                    Status = ConnectionStatus.Connecting;
                }

                break;

            case ConnectionStatus.Connected:

                if (Status != ConnectionStatus.Connected)
                {
                    Status = ConnectionStatus.Connected;
                    MstTimer.Instance.StartCoroutine(Peer.SendDelayedMessages());
                    OnConnectedEvent?.Invoke();
                }

                break;

            case ConnectionStatus.Disconnected:

                if (Status != ConnectionStatus.Disconnected)
                {
                    Status = ConnectionStatus.Disconnected;
                    OnDisconnectedEvent?.Invoke();
                }

                break;
            }
        }
Example #2
0
 public void Connect(string host, int port)
 {
     try {
         IPHostEntry entry = Dns.GetHostEntry(host);
         if (entry != null && entry.AddressList != null)
         {
             for (int AddressListIndex = 0; AddressListIndex < entry.AddressList.Length; AddressListIndex++)
             {
                 if (entry.AddressList[AddressListIndex].AddressFamily == AddressFamily.InterNetwork)
                 {
                     socket?.Close(1000);
                     socket?.Dispose();
                     socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                     SocketAsyncEventArgs connectEventArgs = new SocketAsyncEventArgs();
                     connectEventArgs.Completed     += ConnectEventArgs_Completed;
                     connectEventArgs.RemoteEndPoint = new IPEndPoint(entry.AddressList[AddressListIndex], port);
                     if (!socket.ConnectAsync(connectEventArgs))
                     {
                         ConnectEventArgs_Completed(socket, connectEventArgs);
                     }
                     break;
                 }
             }
         }
     } catch (SocketException se) {
         OnConnectedEvent?.Invoke(false);
         OnSocketExceptionEvent?.Invoke(se);
     }
 }
    private void OnConnected(params object[] args)
    {
        SetConnectionStrength(ConnectionStrength.Connected);
        Strength = ConnectionStrength.Connected;

        OnConnectedEvent?.Invoke();
    }
Example #4
0
        private void OnConnected(object sender, OnConnectedArgs e)
        {
            EvtConnectedArgs connectedArgs = new EvtConnectedArgs()
            {
                BotUsername     = e.BotUsername,
                AutoJoinChannel = e.AutoJoinChannel
            };

            OnConnectedEvent?.Invoke(connectedArgs);
        }
 /// <inheritdoc />
 protected override void OnConnected()
 {
     try
     {
         OnConnectedEvent?.Invoke();
     }
     catch (Exception ex)
     {
         Debug.LogException(ex);
     }
     // Start receive datagrams
     ReceiveAsync();
 }
Example #6
0
        private void AcceptTask(IAsyncResult ar)
        {
            var    tcpClient = server.EndAcceptTcpClient(ar);
            string name      = Dns.GetHostEntry(((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address).HostName;
            int    id        = nextId;

            clients.Add(id, tcpClient);

            OnConnectedEvent?.Invoke(name);

            nextId++;
            server.BeginAcceptTcpClient(AcceptTask, null);
        }
Example #7
0
    private void ProcessPacket(ArraySegment <byte> data)
    {
        bool default_id = data.Array[0] < 134;

        if (data.Array[0] == 134)
        {
            string text = Encoding.UTF8.GetString(data.Array, 1, data.Count - 1);
            if (RakNet_Peer.debugLevel >= RakDebugLevel.Low)
            {
                Debug.Log("[Client] Disconnect reason " + (text.Length > 0 ? text : "empty"));
            }
            disconnect_reason = text;
            return;
        }

        if (default_id)
        {
            switch ((RakNetPacketID)data.Array[0])
            {
            case RakNetPacketID.CONNECTION_REQUEST_ACCEPTED:
                IsConnecting = false;
                IsConnected  = true;
                Debug.Log("[Client] Connected to " + client_peer.address + ":" + client_peer.port);
                OnConnected(client_peer.address, client_peer.port);
                OnConnectedEvent?.Invoke(client_peer.address, client_peer.port);
                break;

            case RakNetPacketID.NO_FREE_INCOMING_CONNECTIONS:
                Disconnect(DisconnectionType.ServerIsFull);
                break;

            case RakNetPacketID.CONNECTION_ATTEMPT_FAILED:
                Disconnect(DisconnectionType.Timeout);
                break;

            case RakNetPacketID.CONNECTION_LOST:
                Disconnect(DisconnectionType.ConnectionLost);
                break;

            case RakNetPacketID.DISCONNECTION_NOTIFICATION:
                Disconnect(DisconnectionType.ConnectionClosed);
                break;
            }
        }
        else
        {
            OnReceivedData(data);
        }
    }
        private void SetupStart()
        {
            EvtConnectedArgs conArgs = new EvtConnectedArgs
            {
                BotUsername     = BotProgram.BotName,
                AutoJoinChannel = string.Empty
            };

            OnConnectedEvent?.Invoke(conArgs);

            EvtJoinedChannelArgs joinedChannelArgs = new EvtJoinedChannelArgs
            {
                BotUsername = BotProgram.BotName,
                Channel     = string.Empty
            };

            OnJoinedChannelEvent?.Invoke(joinedChannelArgs);
        }
        private void SetupStart()
        {
            TRBotLogger.Logger.Information($"\nPlease enter a name to use (no spaces)! This can be an existing name in the database. Skip to use \"{DEFAULT_TERMINAL_USERNAME}\" as the name.");

            string newName = Console.ReadLine();

            Console.WriteLine();

            if (string.IsNullOrEmpty(newName) == true)
            {
                newName = DEFAULT_TERMINAL_USERNAME;
            }
            else
            {
                //Remove all spaces
                newName = Helpers.RemoveAllWhitespace(newName);
            }

            //Set the name
            TerminalUsername = newName;

            EvtConnectedArgs conArgs = new EvtConnectedArgs
            {
                BotUsername     = TerminalUsername,
                AutoJoinChannel = string.Empty
            };

            OnConnectedEvent?.Invoke(conArgs);

            EvtJoinedChannelArgs joinedChannelArgs = new EvtJoinedChannelArgs
            {
                BotUsername = TerminalUsername,
                Channel     = string.Empty
            };

            OnJoinedChannelEvent?.Invoke(joinedChannelArgs);
        }
Example #10
0
        private async Task OnMessage(ResponseMessage message)
        {
            var des = JsonConvert.DeserializeObject <ExileTradeWebSocketMessage>(message.Text);

            if (des?.Auth != null)
            {
                if (des.Auth.Value)
                {
                    OnConnectedEvent?.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    await Stop();
                }
            }

            if (des?.New != null)
            {
                foreach (var id in des.New)
                {
                    OnNewIdRecievedEvent?.Invoke(this, id);
                }
            }
        }
 public override void OnClientConnect(NetworkConnection conn)
 {
     base.OnClientConnect(conn);
     OnConnectedEvent?.Invoke(conn);
 }
Example #12
0
        public virtual void OnConnected(HPacket packet)
        {
            HotelServer      = HotelEndPoint.Parse(packet.ReadUTF8(), packet.ReadInt32());
            ClientVersion    = packet.ReadUTF8();
            ClientIdentifier = packet.ReadUTF8();
            ClientType       = packet.ReadUTF8();
            try
            {
                MessagesInfoIncoming = new List <HMessage>();
                MessagesInfoOutgoing = new List <HMessage>();
                Out = new Outgoing(new List <HMessage>());
                In  = new Incoming(new List <HMessage>());
                int MessagesInfoLenght = packet.ReadInt32();
                foreach (var i in Enumerable.Range(0, MessagesInfoLenght))
                {
                    int    CurrentMessageID         = packet.ReadInt32();
                    string CurrentMessageHash       = packet.ReadUTF8();
                    string CurrentMessageName       = packet.ReadUTF8();
                    string CurrentMessageStructure  = packet.ReadUTF8();
                    bool   CurrentMessageIsOutgoing = packet.ReadBoolean();
                    string CurrentMessageSource     = packet.ReadUTF8();
                    if (string.IsNullOrWhiteSpace(CurrentMessageHash) || CurrentMessageHash == "NULL")
                    {
                        CurrentMessageHash = CurrentMessageName;
                    }
                    CurrentMessageHash = CurrentMessageSource + "_" + CurrentMessageHash;
                    HMessage CurrentHMessage = new HMessage((ushort)CurrentMessageID, CurrentMessageHash, CurrentMessageName, CurrentMessageStructure);
                    if (CurrentMessageIsOutgoing)
                    {
                        MessagesInfoOutgoing.Add(CurrentHMessage);
                    }
                    else
                    {
                        MessagesInfoIncoming.Add(CurrentHMessage);
                    }
                }
                List <HMessage> GeodeOut = new List <HMessage>();
                List <HMessage> GeodeIn  = new List <HMessage>();
                foreach (PropertyInfo GeodeOutProperty in Out.GetType().GetProperties())
                {
                    try
                    {
                        if (GeodeOutProperty.PropertyType == typeof(HMessage))
                        {
                            GeodeOut.Add(MessagesInfoOutgoing.First(x => x.Name == GeodeOutProperty.Name));
                        }
                    }
                    catch { Console.WriteLine("MessageInfo not found for: " + GeodeOutProperty.Name); }
                }
                foreach (PropertyInfo GeodeInProperty in In.GetType().GetProperties())
                {
                    try
                    {
                        if (GeodeInProperty.PropertyType == typeof(HMessage))
                        {
                            GeodeIn.Add(MessagesInfoIncoming.First(x => x.Name == GeodeInProperty.Name));
                        }
                    }
                    catch { Console.WriteLine("MessageInfo not found for: " + GeodeInProperty.Name); }
                }
                Out = new Outgoing(GeodeOut);
                In  = new Incoming(GeodeIn);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Critical MessagesInfo exception: " + ex.Message);
                MessagesInfo_Failed = true;
            }

            IsConnected = true;
            if (DisableEventHandlers == false)
            {
                try { OnConnectedEvent.Invoke(this, packet); } catch { };//Invoke event handler
            }
        }
 private void OnConnected(object sender, EventArgs e)
 {
     IsConnected.Set();
     Debug.Log("Connected to RosBridge: " + RosBridgeServerUrl);
     OnConnectedEvent?.Invoke(this, EventArgs.Empty);
 }
Example #14
0
 protected override void OnHandshaked()
 {
     Console.WriteLine($"Chat SSL client handshaked a new session with Id {Id}");
     OnConnectedEvent?.Invoke(this, EventArgs.Empty);
 }
Example #15
0
 public override void OnConnected(string p0)
 {
     OnConnectedEvent?.Invoke(this, p0);
 }