public void InvokeConnected(object sender, ConnectedEventArgs args) { Connected?.Invoke(sender, args); }
private void OnConnectionConnected(object sender, ConnectedEventArgs args) { Logger.LogDebug($"Incoming from {args.Connection.RemoteEndPoint}"); try { if (IpBanned(args.Connection.RemoteEndPoint.Address, out var playerBan)) { KickConnection(args.Connection, DisconnectReason.Banned, playerBan.GetReasonWithExpiration()); return; } NetIncomingMessage hailMessage = args.Connection.RemoteHailMessage; int version = hailMessage.ReadInt32(); if (version != SharedConstants.Version) { KickConnection(args.Connection, version < SharedConstants.Version ? DisconnectReason.VersionOlder : DisconnectReason.VersionNewer); return; } string playerName = hailMessage.ReadString().Trim(); PlayerMove movementData = hailMessage.ReadPlayerMove(); if (playerName.Length == 0 || playerName.Length > SharedConstants.MaxNameLength) { KickConnection(args.Connection, DisconnectReason.InvalidName); return; } ulong steamId = 0; // Unverified steam id byte[] sessionData = null; bool hasAuth = hailMessage.ReadBoolean(); if (hasAuth) { int sessionLength = hailMessage.ReadInt32(); sessionData = hailMessage.ReadBytes(sessionLength); steamId = hailMessage.ReadUInt64(); } int numWins = hailMessage.ReadInt32(); if (RequireSteamAuth) { if (!hasAuth) { throw new Exception("No steam auth session ticket in hail message."); } if (!SteamServer.Auth.StartSession(sessionData, steamId)) { throw new Exception("Could not start steam session."); } pendingConnections.Add(new PendingConnection(args.Connection, steamId, playerName, movementData)); Logger.LogDebug($"Connection from {args.Connection.RemoteEndPoint}, awaiting steam auth approval..."); } else { AcceptConnection(args.Connection, playerName, movementData, 0, numWins); } } catch (Exception ex) { Logger.LogException(ex); KickConnection(args.Connection, DisconnectReason.InvalidSteamSession, ex.Message); return; } }