Get CLI to a base state
This commit is contained in:
1 parent
068c88de4b
commit
c8a0aef289
2 files changed
+28
-13
No files matched your search
+12
-2
@@ -12,7 +12,11 @@ class clientExample {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onClientConnected(mUDPClient user) {
|
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) {
|
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) {
|
void onClientDisconnected(mUDPClient user) {
|
||||||
Console.WriteLine("User disconnected with username: " + user.UserName);
|
Console.WriteLine("User disconnected from server with username: " + user.UserName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onServerDisconnected() {
|
void onServerDisconnected() {
|
||||||
@@ -42,7 +50,9 @@ class clientExample {
|
|||||||
if (clientObject == null) return;
|
if (clientObject == null) return;
|
||||||
clientObject.onServerConnected += onServerConnected;
|
clientObject.onServerConnected += onServerConnected;
|
||||||
clientObject.onUserConnected += onClientConnected;
|
clientObject.onUserConnected += onClientConnected;
|
||||||
|
clientObject.onUserJoined += onClientJoined;
|
||||||
clientObject.onDataReceived += onReceive;
|
clientObject.onDataReceived += onReceive;
|
||||||
|
clientObject.onUserLeft += onClientLeft;
|
||||||
clientObject.onUserDisconnected += onClientDisconnected;
|
clientObject.onUserDisconnected += onClientDisconnected;
|
||||||
clientObject.onServerDisconnected += onServerDisconnected;
|
clientObject.onServerDisconnected += onServerDisconnected;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.Net.Sockets;
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using MessagePack.Formatters;
|
||||||
using Mistox.ResevedPackets;
|
using Mistox.ResevedPackets;
|
||||||
|
|
||||||
namespace Mistox.Client {
|
namespace Mistox.Client {
|
||||||
@@ -95,13 +96,17 @@ namespace Mistox.Client {
|
|||||||
if (!clientConnections.ContainsKey(remoteHost)) {
|
if (!clientConnections.ContainsKey(remoteHost)) {
|
||||||
mUDPClient newConnection = new mUDPClient(this, remoteHost);
|
mUDPClient newConnection = new mUDPClient(this, remoteHost);
|
||||||
clientConnections[remoteHost] = newConnection;
|
clientConnections[remoteHost] = newConnection;
|
||||||
|
InvokeOnUserJoined(newConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove users that left
|
// Remove users that left
|
||||||
foreach (IPEndPoint key in clientConnections.Keys) {
|
foreach (IPEndPoint key in clientConnections.Keys) {
|
||||||
if (!activeIps.Contains(key.Address)) {
|
if (!activeIps.Contains(key.Address)) {
|
||||||
clientConnections.TryRemove(key, out _);
|
mUDPClient? user;
|
||||||
|
clientConnections.TryRemove(key, out user);
|
||||||
|
if (user == null) return;
|
||||||
|
InvokeOnUserLeft(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,15 +160,15 @@ namespace Mistox.Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// When any user connects to the server (self) hasn't seen yet
|
// When any user connects to the server (self) hasn't seen yet
|
||||||
public event Action<string> onUserJoined;
|
public event Action<mUDPClient> onUserJoined;
|
||||||
public void InvokeOnUserJoined(string UserName){
|
public void InvokeOnUserJoined(mUDPClient User){
|
||||||
onUserJoined?.Invoke(UserName);
|
onUserJoined?.Invoke(User);
|
||||||
}
|
}
|
||||||
|
|
||||||
// When user is within range of (self) and network rendering starts
|
// When user is within range of (self) and network rendering starts
|
||||||
public event Action<mUDPClient> onUserConnected;
|
public event Action<mUDPClient> onUserConnected;
|
||||||
public void InvokeOnUserConnected(mUDPClient ConnectedUser){
|
public void InvokeOnUserConnected(mUDPClient User){
|
||||||
onUserConnected?.Invoke(ConnectedUser);
|
onUserConnected?.Invoke(User);
|
||||||
}
|
}
|
||||||
|
|
||||||
// When generic data is received
|
// When generic data is received
|
||||||
@@ -189,14 +194,14 @@ namespace Mistox.Client {
|
|||||||
|
|
||||||
// When user is no longer in range of (self) and network rendering stops
|
// When user is no longer in range of (self) and network rendering stops
|
||||||
public event Action<mUDPClient> onUserDisconnected;
|
public event Action<mUDPClient> onUserDisconnected;
|
||||||
public void InvokeOnUserDisconnected(mUDPClient DisconnectedUser){
|
public void InvokeOnUserDisconnected(mUDPClient User){
|
||||||
onUserDisconnected?.Invoke(DisconnectedUser);
|
onUserDisconnected?.Invoke(User);
|
||||||
}
|
}
|
||||||
|
|
||||||
// When any user disconnects from the server that isn't (self)
|
// When any user disconnects from the server that isn't (self)
|
||||||
public event Action<string> onUserLeft;
|
public event Action<mUDPClient> onUserLeft;
|
||||||
public void InvokeOnUserLeft(string UserName){
|
public void InvokeOnUserLeft(mUDPClient User){
|
||||||
onUserLeft?.Invoke(UserName);
|
onUserLeft?.Invoke(User);
|
||||||
}
|
}
|
||||||
|
|
||||||
// When (self) disconnects to the server
|
// When (self) disconnects to the server
|
||||||
|
|||||||
Reference in new issue
Block a user