Compare commits
2
Commits
068c88de4b
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7581fbdeb | ||
|
|
c8a0aef289 |
No files matched your search
+12
-2
@@ -12,7 +12,11 @@ class clientExample {
|
||||
}
|
||||
|
||||
void onClientConnected(mUDPClient user) {
|
||||
Console.WriteLine("User connected with username: " + user.UserName);
|
||||
Console.WriteLine("User connected to server with username: " + user.UserName);
|
||||
}
|
||||
|
||||
void onClientJoined(mUDPClient user) {
|
||||
Console.WriteLine("User is now in range of you and UDP connections started with user : " + user.UserName);
|
||||
}
|
||||
|
||||
void onReceive(mUDPClient? user, dynamic data) {
|
||||
@@ -29,8 +33,12 @@ class clientExample {
|
||||
}
|
||||
}
|
||||
|
||||
void onClientLeft(mUDPClient user) {
|
||||
Console.WriteLine("User is no longer in range of you and UDP connections ended with user : " + user.UserName);
|
||||
}
|
||||
|
||||
void onClientDisconnected(mUDPClient user) {
|
||||
Console.WriteLine("User disconnected with username: " + user.UserName);
|
||||
Console.WriteLine("User disconnected from server with username: " + user.UserName);
|
||||
}
|
||||
|
||||
void onServerDisconnected() {
|
||||
@@ -42,7 +50,9 @@ class clientExample {
|
||||
if (clientObject == null) return;
|
||||
clientObject.onServerConnected += onServerConnected;
|
||||
clientObject.onUserConnected += onClientConnected;
|
||||
clientObject.onUserJoined += onClientJoined;
|
||||
clientObject.onDataReceived += onReceive;
|
||||
clientObject.onUserLeft += onClientLeft;
|
||||
clientObject.onUserDisconnected += onClientDisconnected;
|
||||
clientObject.onServerDisconnected += onServerDisconnected;
|
||||
}
|
||||
|
||||
@@ -36,14 +36,6 @@ namespace Mistox.Client {
|
||||
UserName = userName;
|
||||
ConnectionKey = connectionKey;
|
||||
|
||||
onServerConnected += () => {};
|
||||
onUserConnected += (_) => {};
|
||||
onUserJoined += (_) => {};
|
||||
onDataReceived += (_,_) => {};
|
||||
onUserLeft += (_) => {};
|
||||
onUserDisconnected += (_) => {};
|
||||
onServerDisconnected += () => {};
|
||||
|
||||
// Create and connect to server on TCP
|
||||
Console.WriteLine( "The client is initilized and trying to connect to the server at ip : " + Server.Address );
|
||||
try {
|
||||
@@ -95,13 +87,17 @@ namespace Mistox.Client {
|
||||
if (!clientConnections.ContainsKey(remoteHost)) {
|
||||
mUDPClient newConnection = new mUDPClient(this, remoteHost);
|
||||
clientConnections[remoteHost] = newConnection;
|
||||
InvokeOnUserJoined(newConnection);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove users that left
|
||||
foreach (IPEndPoint key in clientConnections.Keys) {
|
||||
if (!activeIps.Contains(key.Address)) {
|
||||
clientConnections.TryRemove(key, out _);
|
||||
mUDPClient? user;
|
||||
clientConnections.TryRemove(key, out user);
|
||||
if (user == null) return;
|
||||
InvokeOnUserLeft(user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +139,7 @@ namespace Mistox.Client {
|
||||
/////////////////////////////
|
||||
|
||||
// When (self) connects to the server
|
||||
public event Action onServerConnected;
|
||||
public event Action? onServerConnected;
|
||||
public void InvokeOnServerConnected(){
|
||||
Alive = true;
|
||||
Task.Run(async () => {
|
||||
@@ -155,19 +151,19 @@ namespace Mistox.Client {
|
||||
}
|
||||
|
||||
// When any user connects to the server (self) hasn't seen yet
|
||||
public event Action<string> onUserJoined;
|
||||
public void InvokeOnUserJoined(string UserName){
|
||||
onUserJoined?.Invoke(UserName);
|
||||
public event Action<mUDPClient>? onUserJoined;
|
||||
public void InvokeOnUserJoined(mUDPClient User){
|
||||
onUserJoined?.Invoke(User);
|
||||
}
|
||||
|
||||
// When user is within range of (self) and network rendering starts
|
||||
public event Action<mUDPClient> onUserConnected;
|
||||
public void InvokeOnUserConnected(mUDPClient ConnectedUser){
|
||||
onUserConnected?.Invoke(ConnectedUser);
|
||||
public event Action<mUDPClient>? onUserConnected;
|
||||
public void InvokeOnUserConnected(mUDPClient User){
|
||||
onUserConnected?.Invoke(User);
|
||||
}
|
||||
|
||||
// When generic data is received
|
||||
public event Action<mUDPClient?, dynamic> onDataReceived;
|
||||
public event Action<mUDPClient?, dynamic>? onDataReceived;
|
||||
public void InvokeOnReceived(dynamic DataPacket, mUDPClient? remote = null){
|
||||
switch (DataPacket as object) {
|
||||
case HeartbeatPacket packet:
|
||||
@@ -188,19 +184,19 @@ namespace Mistox.Client {
|
||||
}
|
||||
|
||||
// When user is no longer in range of (self) and network rendering stops
|
||||
public event Action<mUDPClient> onUserDisconnected;
|
||||
public void InvokeOnUserDisconnected(mUDPClient DisconnectedUser){
|
||||
onUserDisconnected?.Invoke(DisconnectedUser);
|
||||
public event Action<mUDPClient>? onUserDisconnected;
|
||||
public void InvokeOnUserDisconnected(mUDPClient User){
|
||||
onUserDisconnected?.Invoke(User);
|
||||
}
|
||||
|
||||
// When any user disconnects from the server that isn't (self)
|
||||
public event Action<string> onUserLeft;
|
||||
public void InvokeOnUserLeft(string UserName){
|
||||
onUserLeft?.Invoke(UserName);
|
||||
public event Action<mUDPClient>? onUserLeft;
|
||||
public void InvokeOnUserLeft(mUDPClient User){
|
||||
onUserLeft?.Invoke(User);
|
||||
}
|
||||
|
||||
// When (self) disconnects to the server
|
||||
public event Action onServerDisconnected;
|
||||
public event Action? onServerDisconnected;
|
||||
public void InvokeOnServerDisconnected(){
|
||||
Alive = false;
|
||||
onServerDisconnected?.Invoke();
|
||||
|
||||
@@ -22,9 +22,6 @@ namespace Mistox.Server {
|
||||
public MistoxServer(IPEndPoint ListenerAddress, string serverName) {
|
||||
ServerName = serverName;
|
||||
Listener = new ServerListener(ListenerAddress, this);
|
||||
onUserConnected += (_) => {};
|
||||
onDataReceived += (_, _) => {};
|
||||
onUserDisconnected += (_) => {};
|
||||
Console.WriteLine( "The Server is initilized and waiting for clients to connect at port : " + ListenerAddress.Port );
|
||||
}
|
||||
|
||||
@@ -75,13 +72,13 @@ namespace Mistox.Server {
|
||||
// Events
|
||||
/////////////////////////////
|
||||
|
||||
public event Action<ServerConnection> onUserConnected;
|
||||
public event Action<ServerConnection>? onUserConnected;
|
||||
public void InvokeUserConnected( ServerConnection user ){
|
||||
Connections[user.UserName] = user;
|
||||
onUserConnected?.Invoke( user );
|
||||
}
|
||||
|
||||
public event Action<ServerConnection, object> onDataReceived;
|
||||
public event Action<ServerConnection, object>? onDataReceived;
|
||||
public void InvokeDataReceived( ServerConnection user, dynamic data ){
|
||||
switch (data) {
|
||||
case UserAuthPacket packet when !user.IsAuthenticated:
|
||||
@@ -104,7 +101,7 @@ namespace Mistox.Server {
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<ServerConnection> onUserDisconnected;
|
||||
public event Action<ServerConnection>? onUserDisconnected;
|
||||
public void InvokeUserDisconnected( ServerConnection user ){
|
||||
Connections.Remove(user.UserName, out _);
|
||||
onUserDisconnected?.Invoke( user );
|
||||
|
||||
Reference in new issue
Block a user