Impliment user auth on server
This commit is contained in:
1 parent
007f87f986
commit
974b5c4f0a
2 files changed
+29
-14
No files matched your search
@@ -49,21 +49,23 @@ namespace Mistox.Server {
|
|||||||
onUserConnected?.Invoke( user );
|
onUserConnected?.Invoke( user );
|
||||||
}
|
}
|
||||||
|
|
||||||
public event Action<dynamic> onDataReceived;
|
public event Action<ServerConnection, dynamic> onDataReceived;
|
||||||
public void InvokeDataReceived( ServerConnection user, dynamic data ){
|
public void InvokeDataReceived( ServerConnection user, dynamic data ){
|
||||||
switch (data as object) {
|
switch (data as object) {
|
||||||
case UserAuthPacket packet:
|
case UserAuthPacket packet:
|
||||||
Task.Run(async () => {
|
if (!user.IsAuthenticated) {
|
||||||
try {
|
Task.Run(async () => {
|
||||||
await ProcessAuthRequest(user, packet);
|
try {
|
||||||
} catch {}
|
await ProcessAuthRequest(user, packet);
|
||||||
});
|
} catch {}
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case null:
|
case null:
|
||||||
Console.WriteLine("Received a null packet.");
|
Console.WriteLine("Received a null packet.");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
onDataReceived?.Invoke(data);
|
onDataReceived?.Invoke(user, data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Numerics;
|
||||||
using Mistox.Attributes;
|
using Mistox.Attributes;
|
||||||
|
|
||||||
namespace Mistox.ResevedPackets {
|
namespace Mistox.ResevedPackets {
|
||||||
|
|
||||||
// Packet sent to clients when they are in range telling them to connect together
|
|
||||||
[mPacket]
|
|
||||||
public class UserConnectedPacket {
|
|
||||||
public string UserName { get; set; }
|
|
||||||
public IPAddress ClientIPAddress { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Implimented
|
||||||
// Packet send to server for Auth and responded to the client with Auth Success
|
// Packet send to server for Auth and responded to the client with Auth Success
|
||||||
[mPacket]
|
[mPacket]
|
||||||
public class UserAuthPacket {
|
public class UserAuthPacket {
|
||||||
@@ -22,6 +17,7 @@ namespace Mistox.ResevedPackets {
|
|||||||
public int AuthSuccessful { get; set; } = 0; // 0 is standard, -1 is auth failure, 1 is auth success
|
public int AuthSuccessful { get; set; } = 0; // 0 is standard, -1 is auth failure, 1 is auth success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not Implimented
|
||||||
// Generic networked object packet
|
// Generic networked object packet
|
||||||
[mPacket]
|
[mPacket]
|
||||||
public class EntityPacket {
|
public class EntityPacket {
|
||||||
@@ -34,6 +30,23 @@ namespace Mistox.ResevedPackets {
|
|||||||
public byte[] InnerPayload { get; set; }
|
public byte[] InnerPayload { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not implemented
|
||||||
|
// Packet sent to all clients when a users TCP stream connects to the server
|
||||||
|
[mPacket]
|
||||||
|
public class UserConnectedPacket {
|
||||||
|
public string UserName { get; set; }
|
||||||
|
public IPAddress ClientIPAddress { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not implemented
|
||||||
|
// Packet sent to all clients when a global position update occurrs
|
||||||
|
[mPacket]
|
||||||
|
public class UserPositionUpdatePacket {
|
||||||
|
public string UserName { get; set; }
|
||||||
|
public Vector3 Position { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not implimented
|
||||||
// Packet sent to all clients when a users TCP stream disconnects from the server
|
// Packet sent to all clients when a users TCP stream disconnects from the server
|
||||||
[mPacket]
|
[mPacket]
|
||||||
public class UserDisconnectedPacket {
|
public class UserDisconnectedPacket {
|
||||||
|
|||||||
Reference in new issue
Block a user