private void ConnectionReceived(object sender, NewConnectionEventArgs e) { if (Engine.ConnectionManager.ShouldBanPeer(e.Peer)) { e.Connection.Dispose(); return; } var id = new PeerId(e.Peer, e.TorrentManager) { Connection = e.Connection }; //Debug.WriteLine("ListenManager - ConnectionReceived: {0}", id.Connection); if (id.Connection.IsIncoming) { var skeys = new List <InfoHash>(); ClientEngine.MainLoop.QueueWait(delegate { skeys.AddRange(Engine.Torrents.Select(t => t.InfoHash)); }); EncryptorFactory.BeginCheckEncryption(id, HandshakeMessage.HandshakeLength, _endCheckEncryptionCallback, id, skeys.ToArray()); } else { ClientEngine.MainLoop.Queue(delegate { Engine.ConnectionManager.ProcessFreshConnection(id); }); } }
private void OnNewConnection(NewConnectionEventArgs e) { try { // Handshake. var clientVersion = e.HandshakeData.ReadInt32(); var clientName = e.HandshakeData.ReadString(); e.HandshakeData.Recycle(); if (clientVersion != 50516550) { using (var packet = MessageWriter.Get(SendOption.Reliable)) { Message01JoinGame.SerializeError(packet, false, DisconnectReason.IncorrectVersion); e.Connection.Send(packet); } return; } // Create client. _clientManager.Create(clientName, e.Connection); } catch (Exception ex) { _logger.LogError(ex, "Error in new connection."); } }
private void NewPeerConnected(object sender, NewConnectionEventArgs args) { PerformanceCounters.IncommingConnections.Increment(); var connection = new Connection(args.Socket); RegisterPeer(connection); }
void OnTWSTServerEventNewConnection(object sender, NewConnectionEventArgs e) { try { //New Socket arrived LOG.Info("{Message}", $"RES REQ Service: New connection arrived from {e.Socket.RemoteEndPoint}"); if (mCurrentDate.Date != DateTime.Now.Date) { mIPConnectedList.Clear(); mCurrentDate = DateTime.Now.Date; } IPEndPoint remoteEndPoint = (IPEndPoint)e.Socket.RemoteEndPoint; if (!mIPConnectedList.Contains(remoteEndPoint.Address.ToString()) && mIPConnectedList.Count < mMaxLicensedQty) { mIPConnectedList.Add(remoteEndPoint.Address.ToString()); } var reqInstance = new RESGeoITDReqInstance(e.Socket); new Thread(reqInstance.StartProcess).Start(); } catch (Exception ex) { LOG.Fatal(ex, "{Message}", "Exception caught."); } finally { LOG.Trace("EXIT"); } }
private void NewConnectionHandler(object sender, NewConnectionEventArgs args) { Console.WriteLine("New connection from " + args.Connection.EndPoint.ToString()); clients.Add(args.Connection); args.Connection.DataReceived += this.DataReceivedHandler; args.Connection.Disconnected += this.ClientDisconnectHandler; args.Recycle(); }
public static void Postfix([HarmonyArgument(0)] NewConnectionEventArgs evt) { var writer = MessageWriter.Get(SendOption.Reliable); ModdedHandshakeS2C.Serialize(writer, "Among Us", Application.version, 0); evt.Connection.Send(writer); writer.Recycle(); }
static void NewConnectionHandler(object sender, NewConnectionEventArgs args) { args.Connection.DataReceived += DataReceivedHandler; args.Connection.Disconnected += DisconnectionHandler; Console.WriteLine("New connection from " + args.Connection.EndPoint.ToString()); args.Recycle(); }
private void OnClientConnected(object sender, NewConnectionEventArgs e) { const int packetSize = 8 * 1024; var client = new HttpClient(new TcpClient(e.Socket, packetSize)); client.OnClientDisconnected += OnClientDisconnected; Clients.Add(client); client.Begin(); }
private async ValueTask OnNewConnection(NewConnectionEventArgs e) { // Handshake. ModdedHandshakeC2S.Deserialize(e.HandshakeData, out var clientVersion, out var name, out var mods); var connection = new HazelConnection(e.Connection, _connectionLogger); // Register client await _clientManager.RegisterConnectionAsync(connection, name, clientVersion, mods); }
private void OnClientConnected(object sender, NewConnectionEventArgs e) { var client = new SocksClient(new TcpClient(e.Socket, PacketSize)); client.OnClientDisconnected += OnClientDisconnected; client.OnClientAuthenticating += OnClientAuthenticating; Clients.Add(client); client.Authentication = Authentication; client.Begin(PacketSize, Timeout); }
/// <summary> /// New connection event handler. /// Connect this to one of the Listener classes. /// Using this method, there is no way of knowing whether or not the session was successfully added. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The <see cref="NewConnectionEventArgs"/> instance containing the event data.</param> /// <exception cref="System.InvalidOperationException">SessionFactory is null!</exception> public async void NewConnectionEventHandlerAsync(object sender, NewConnectionEventArgs e) { if (null == SessionFactory) { throw new InvalidOperationException("SessionFactory is null!"); } NetworkSession session = SessionFactory.Create(e.Socket); await AddAsync(session).ConfigureAwait(false); }
public void HandleNewConnection(object sender, NewConnectionEventArgs a) { lock (DataLock) { var blockchain = new Blockchain(a.Connect); Blockchains.Add(blockchain); BlockchainsBestBlock.Add(null); blockchain.NewBestBlock += new EventHandler <NewBestBlockEventArgs>(HandleNewBestBlock); NewBlockchain?.Invoke(this, new NewBlockchainEventArgs(blockchain)); } }
private async ValueTask OnNewConnection(NewConnectionEventArgs e) { // Handshake. var clientVersion = e.HandshakeData.ReadInt32(); var name = e.HandshakeData.ReadString(); var connection = new HazelConnection(e.Connection, _connectionLogger); // Register client await _clientManager.RegisterConnectionAsync(connection, name, clientVersion); }
/// <summary> /// News the connection handler. /// </summary> /// <param name="sender">Sender.</param> /// <param name="args">Arguments.</param> private void NewConnectionHandler(object sender, NewConnectionEventArgs args) { string UID = RandomIdGenerator.GetBase62(6); Console.WriteLine("UID Created: " + UID); //https://www.dotnetperls.com/keyvaluepair clients.Add(new KeyValuePair <string, Connection>(UID, args.Connection)); Console.WriteLine("New connection from " + args.Connection.EndPoint.ToString() + " with UID: " + UID); args.Connection.DataReceived += this.DataReceivedHandler; args.Connection.Disconnected += this.ClientDisconnectHandler; args.Recycle(); }
private async ValueTask OnNewConnection(NewConnectionEventArgs e) { // Handshake. HandshakeC2S.Deserialize(e.HandshakeData, out int clientVersion, out var name, out _); var connection = new HazelConnection(e.Connection, _connectionLogger); await _eventManager.CallAsync(new ClientConnectionEvent(connection, e.HandshakeData)); // Register client await _clientManager.RegisterConnectionAsync(connection, name, clientVersion); }
private void Server_NewConnection(NewConnectionEventArgs obj) { var connection = connectionProvider.Get(obj.HandshakeData, obj.Connection as UdpConnection); if (connection == null) { return; } connection.Disconnected += Connection_Disconnected; lock (mutex) { this.connections.Add(connection); } }
private ValueTask ConnectionOnNewConnection(NewConnectionEventArgs e) { MessageHandshake.Deserialize(e.HandshakeData, out var clientVersion, out var platform, out var clientId); _logger.LogTrace("New authentication request: {clientVersion}, {platform}, {clientId}", clientVersion, platform, clientId); using var writer = MessageWriter.Get(MessageType.Reliable); writer.StartMessage(1); Message01Complete.Serialize(writer, (uint)RandomNumberGenerator.GetInt32(int.MinValue, int.MaxValue)); writer.EndMessage(); return(e.Connection.SendAsync(writer)); }
private async ValueTask OnNewConnection(NewConnectionEventArgs e) { MessageHello.Deserialize(e.HandshakeData, out int announcementVersion, out int id, out Language language); _logger.LogDebug("Client requested announcement (version: {Version}, id: {Id}, language: {Language})", announcementVersion, id, language); if (announcementVersion != 2) { await e.Connection.Disconnect("Unsupported announcement version"); return; } var @event = new AnnouncementRequestEvent(id, language); await _eventManager.CallAsync(@event); var response = @event.Response; if (response.UseCached) { using var writer = MessageWriter.Get(MessageType.Reliable); Message00UseCache.Serialize(writer); await e.Connection.SendAsync(writer); _logger.LogDebug("Sent UseCache response"); } if (response.Announcement != null) { using var writer = MessageWriter.Get(MessageType.Reliable); Announcement announcement = response.Announcement.Value; Message01Update.Serialize(writer, announcement.Id, announcement.Message); await e.Connection.SendAsync(writer); _logger.LogDebug("Sent ({Id}) {Message}", announcement.Id, announcement.Message); } if (response.FreeWeekendState != FreeWeekendState.NotFree) { using var writer = MessageWriter.Get(MessageType.Reliable); Message02SetFreeWeekend.Serialize(writer, response.FreeWeekendState); await e.Connection.SendAsync(writer); _logger.LogDebug("Sent {FreeWeekendState} weekend state", response.FreeWeekendState); } await e.Connection.Disconnect(null); }
private void OnNewConnection(NewConnectionEventArgs e) { // Handshake. var clientVersion = e.HandshakeData.ReadInt32(); var clientName = e.HandshakeData.ReadString(); e.HandshakeData.Recycle(); if (clientVersion != 50516550) { e.Connection.Send(new Message1DisconnectReason(DisconnectReason.IncorrectVersion)); return; } // Register client. _clientManager.Add(new Client(_clientManager, _gameManager, _clientManager.NextId(), clientName, e.Connection)); }
private void Listener_NewConnection(NewConnectionEventArgs obj) { try { if (!WillSend) { obj.Connection.Dispose(); return; } lock (Message) { obj.Connection.Send(Message); } obj.Connection.Send(DisconnectMessage); obj.Connection.Dispose(); } catch (Exception e) { Master.LogManager.LogError(e.ToString(), Shared.ErrorLocation.AnnouncementServer); } }
private async ValueTask OnNewConnection(NewConnectionEventArgs e) { MessageHello.Deserialize(e.HandshakeData, out var announcementVersion, out var id, out var language); if (announcementVersion != 2) { await e.Connection.Disconnect("Unsupported announcement version"); return; } var @event = new AnnouncementRequestEvent(id, language); await _eventManager.CallAsync(@event); var response = @event.Response; if (response.UseCached) { using var writer = MessageWriter.Get(MessageType.Reliable); Message00UseCache.Serialize(writer); await e.Connection.SendAsync(writer); } if (response.Announcement != null) { using var writer = MessageWriter.Get(MessageType.Reliable); var announcement = response.Announcement.Value; Message01Update.Serialize(writer, announcement.Id, announcement.Message); await e.Connection.SendAsync(writer); } if (response.FreeWeekendState != FreeWeekendState.NotFree) { using var writer = MessageWriter.Get(MessageType.Reliable); Message02SetFreeWeekend.Serialize(writer, response.FreeWeekendState); await e.Connection.SendAsync(writer); } await e.Connection.Disconnect(null); }
// From here down, you must be thread-safe! private void HandleNewConnection(NewConnectionEventArgs obj) { try { if (obj.HandshakeData.Length <= 0) { // If the handshake is invalid, let's disconnect them! return; } // Make sure this client version is compatible with this server and/or other clients! var clientVersion = obj.HandshakeData.ReadInt32(); var player = new Player(this, clientVersion); obj.Connection.DataReceived += player.HandleMessage; obj.Connection.Disconnected += HandleDisconnect; } finally { // Always recycle messages! obj.HandshakeData.Recycle(); } }
void HandleNewConnection(object sender, NewConnectionEventArgs a) { ConnectionListBox.Items.Add(a.Connect); }