2021-09-27 20:28:27 +02:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
|
|
|
|
using Lidgren.Network;
|
2021-09-26 20:52:23 -06:00
|
|
|
|
|
|
|
|
|
namespace CoopClient
|
|
|
|
|
{
|
|
|
|
|
public static class Interface
|
|
|
|
|
{
|
2021-09-27 19:10:51 +02:00
|
|
|
|
#region DELEGATES
|
|
|
|
|
public delegate void ConnectEvent(bool connected, string bye_message = null);
|
2021-09-26 20:52:23 -06:00
|
|
|
|
public delegate void MessageEvent(NetIncomingMessage message);
|
2021-09-27 20:28:27 +02:00
|
|
|
|
public delegate void ChatMessage(string from, string message, CancelEventArgs args);
|
2021-09-27 19:10:51 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region EVENTS
|
|
|
|
|
public static event ConnectEvent OnConnected;
|
|
|
|
|
public static event ConnectEvent OnDisconnected;
|
2021-09-26 20:52:23 -06:00
|
|
|
|
public static event MessageEvent OnMessage;
|
2021-09-27 20:28:27 +02:00
|
|
|
|
public static event ChatMessage OnChatMessage;
|
2021-09-26 20:52:23 -06:00
|
|
|
|
|
2021-09-27 19:10:51 +02:00
|
|
|
|
public static void Connected()
|
2021-09-26 20:52:23 -06:00
|
|
|
|
{
|
2021-09-27 19:10:51 +02:00
|
|
|
|
OnConnected?.Invoke(true);
|
2021-09-26 20:52:23 -06:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 19:10:51 +02:00
|
|
|
|
public static void Disconnected(string bye_message)
|
2021-09-26 20:52:23 -06:00
|
|
|
|
{
|
2021-09-27 19:10:51 +02:00
|
|
|
|
OnDisconnected?.Invoke(false, bye_message);
|
2021-09-26 20:52:23 -06:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 19:10:51 +02:00
|
|
|
|
public static void MessageReceived(NetIncomingMessage message)
|
2021-09-26 20:52:23 -06:00
|
|
|
|
{
|
2021-09-27 19:10:51 +02:00
|
|
|
|
OnMessage?.Invoke(message);
|
2021-09-26 20:52:23 -06:00
|
|
|
|
}
|
2021-09-27 20:28:27 +02:00
|
|
|
|
|
|
|
|
|
public static bool ChatMessageReceived(string from, string message)
|
|
|
|
|
{
|
|
|
|
|
CancelEventArgs args = new CancelEventArgs(false);
|
|
|
|
|
OnChatMessage?.Invoke(from, message, args);
|
|
|
|
|
return args.Cancel;
|
|
|
|
|
}
|
2021-09-27 19:10:51 +02:00
|
|
|
|
#endregion
|
2021-09-26 20:52:23 -06:00
|
|
|
|
|
2021-09-27 20:28:27 +02:00
|
|
|
|
public static void SendChatMessage(string from, string message)
|
|
|
|
|
{
|
|
|
|
|
Main.MainChat.AddMessage(from, message);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 19:10:51 +02:00
|
|
|
|
public static void Connect(string serverAddress)
|
2021-09-26 20:52:23 -06:00
|
|
|
|
{
|
2021-09-27 19:10:51 +02:00
|
|
|
|
Main.MainNetworking.DisConnectFromServer(serverAddress);
|
2021-09-26 20:52:23 -06:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 19:10:51 +02:00
|
|
|
|
public static void Configure(string playerName, bool shareNpcsWithPlayers, int streamedNpcs, bool debug = false)
|
2021-09-26 20:52:23 -06:00
|
|
|
|
{
|
2021-09-27 19:10:51 +02:00
|
|
|
|
Main.MainSettings.Username = playerName;
|
|
|
|
|
Main.ShareNpcsWithPlayers = shareNpcsWithPlayers;
|
|
|
|
|
Main.MainSettings.StreamedNpc = streamedNpcs;
|
|
|
|
|
#if DEBUG
|
|
|
|
|
Main.UseDebug = debug;
|
|
|
|
|
#endif
|
2021-09-26 20:52:23 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|