pogrammerX
pogrammerX
CC#
Created by pogrammerX on 10/15/2023 in #help
❔ C# Self Signed certificate with SslStream
My Code:
var listener = new TcpListener(IPAddress.Any, 443); // Port 443 is typically used for HTTPS

listener.Start();

X509Certificate2 serverCertificate = new X509Certificate2("C:\\Users\\pogrammerX\\XXXXXXX\\XXXServer\\XXXServer\\bin\\Debug\\net6.0\\certificate.pfx", "password");

while (true)
{
Console.WriteLine("Waiting for a connection...");
var client = listener.AcceptTcpClient();

// Create an SSL stream using the client's network stream and the server certificate.
var q = client.GetStream();
var sslStream = new SslStream(q);
sslStream.AuthenticateAsServer(serverCertificate, false, System.Security.Authentication.SslProtocols.Tls, true);

Console.WriteLine("Connected!");

byte[] buffer = new byte[client.ReceiveBufferSize];
int bytesRead;

while ((bytesRead = sslStream.Read(buffer, 0, client.ReceiveBufferSize)) > 0)
{
string message = Encoding.UTF8.GetString(buffer, 0, bytesRead);
Console.WriteLine("Received: " + message);
}

sslStream.Close();
client.Close();
}
var listener = new TcpListener(IPAddress.Any, 443); // Port 443 is typically used for HTTPS

listener.Start();

X509Certificate2 serverCertificate = new X509Certificate2("C:\\Users\\pogrammerX\\XXXXXXX\\XXXServer\\XXXServer\\bin\\Debug\\net6.0\\certificate.pfx", "password");

while (true)
{
Console.WriteLine("Waiting for a connection...");
var client = listener.AcceptTcpClient();

// Create an SSL stream using the client's network stream and the server certificate.
var q = client.GetStream();
var sslStream = new SslStream(q);
sslStream.AuthenticateAsServer(serverCertificate, false, System.Security.Authentication.SslProtocols.Tls, true);

Console.WriteLine("Connected!");

byte[] buffer = new byte[client.ReceiveBufferSize];
int bytesRead;

while ((bytesRead = sslStream.Read(buffer, 0, client.ReceiveBufferSize)) > 0)
{
string message = Encoding.UTF8.GetString(buffer, 0, bytesRead);
Console.WriteLine("Received: " + message);
}

sslStream.Close();
client.Close();
}
Commands used to generate the self signed certificate:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout privatekey.key -out certificate.crt -subj "/C=US/ST=State/L=City/O=Organization/CN=127.0.0.1"
openssl pkcs12 -export -out certificate.pfx -inkey privatekey.key -in certificate.crt -passout pass:password
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout privatekey.key -out certificate.crt -subj "/C=US/ST=State/L=City/O=Organization/CN=127.0.0.1"
openssl pkcs12 -export -out certificate.pfx -inkey privatekey.key -in certificate.crt -passout pass:password
where this line:
sslStream.AuthenticateAsServer(serverCertificate, false, System.Security.Authentication.SslProtocols.Tls, true);
sslStream.AuthenticateAsServer(serverCertificate, false, System.Security.Authentication.SslProtocols.Tls, true);
throws: System.IO.IOException: 'Cannot determine the frame size or a corrupted frame was received.' After further testing it seems like serverCertificate has some issues, any help is appreciated
2 replies
CC#
Created by pogrammerX on 10/5/2023 in #help
❔ Copy a file thats in use (using Shadow Copy or something)
Can someone please help me get this code to shadow copy?
private string CopyToTempFile(string sourceFilePath)
{
string destinationFilePath = GetTempFilePath();
while(File.Exists(destinationFilePath))
destinationFilePath = GetTempFilePath();


return destinationFilePath;
}
private string CopyToTempFile(string sourceFilePath)
{
string destinationFilePath = GetTempFilePath();
while(File.Exists(destinationFilePath))
destinationFilePath = GetTempFilePath();


return destinationFilePath;
}
7 replies
CC#
Created by pogrammerX on 2/14/2023 in #help
❔ BulletSharp FPS Controller
can someone help me with my FPS controller in my game engine, im using bullet sharp this is my code:
System.Numerics.Vector3 GetHorizontalDirection(System.Numerics.Vector3 cameraForward)
{
return new SVector3(cameraForward.X, 0, cameraForward.Z);
}

float speed = 1f;
float x = 0f;
float z = 0f;

if (Keyboard.IsKeyDown(Key.W)) z = 1f;
if (Keyboard.IsKeyDown(Key.S)) z = -1f;
if (Keyboard.IsKeyDown(Key.A)) x = -1f;
if (Keyboard.IsKeyDown(Key.D)) x = 1f;

var move = GetHorizontalDirection(Player.CameraForward) * z + Player.CameraRight * x;

if (Keyboard.IsKeyDown(Key.Space) && IsGrounded())
{
if (Player.playerBody != null) Player.playerBody.LinearVelocity = new SVector3(move.X * speed, Player.JumpVelocity, move.Z * speed);
ThreadPool.QueueUserWorkItem(UpdateSoundEnginePlayerParams, null, false);
}
else if (Player.playerBody != null)
{
Player.playerBody.LinearVelocity = new SVector3(move.X * speed, Player.playerBody.LinearVelocity.Y, move.Z * speed);
ThreadPool.QueueUserWorkItem(UpdateSoundEnginePlayerParams, null, false);
}
System.Numerics.Vector3 GetHorizontalDirection(System.Numerics.Vector3 cameraForward)
{
return new SVector3(cameraForward.X, 0, cameraForward.Z);
}

float speed = 1f;
float x = 0f;
float z = 0f;

if (Keyboard.IsKeyDown(Key.W)) z = 1f;
if (Keyboard.IsKeyDown(Key.S)) z = -1f;
if (Keyboard.IsKeyDown(Key.A)) x = -1f;
if (Keyboard.IsKeyDown(Key.D)) x = 1f;

var move = GetHorizontalDirection(Player.CameraForward) * z + Player.CameraRight * x;

if (Keyboard.IsKeyDown(Key.Space) && IsGrounded())
{
if (Player.playerBody != null) Player.playerBody.LinearVelocity = new SVector3(move.X * speed, Player.JumpVelocity, move.Z * speed);
ThreadPool.QueueUserWorkItem(UpdateSoundEnginePlayerParams, null, false);
}
else if (Player.playerBody != null)
{
Player.playerBody.LinearVelocity = new SVector3(move.X * speed, Player.playerBody.LinearVelocity.Y, move.Z * speed);
ThreadPool.QueueUserWorkItem(UpdateSoundEnginePlayerParams, null, false);
}
Player.playerBody is the RigidBody of the player. the issue is that when i walk straight i walk like forward left
2 replies
CC#
Created by pogrammerX on 1/11/2023 in #help
❔ Bullet World.Step causes 0xC000001D Illegal Instruction (C BulletSharp)
So i am using BulletSharp in my project. This is the code i use to step it: if (settingScene) return; if ((float)simTime.Elapsed.TotalSeconds < time) { time = 0; timeStep = 0; } timeStep = ((float)simTime.Elapsed.TotalSeconds - time); time = (float)simTime.Elapsed.TotalSeconds; world.StepSimulation(timeStep, 7); Everything works fine as long as i only add BoxShapes, but as soon as i add a ConvexHullShape it starts crashing.
8 replies