#undef DEBUG
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using RageCoop.Core;
namespace RageCoop.Client
{
///
/// ?
///
public static class COOPAPI
{
#region DELEGATES
///
/// ?
///
///
/// The player's id
///
public delegate void ConnectEvent(bool connected, int from, string reason = null);
///
/// ?
///
///
/// The Lidgren-Network net handle
///
public delegate void ChatMessage(string from, string message, CancelEventArgs args);
///
/// ?
///
/// The Lidgren-Network net handle
///
///
///
public delegate void ModEvent(long from, string mod, byte customID, byte[] bytes);
#endregion
#region EVENTS
///
/// ?
///
public static event ConnectEvent OnConnection;
///
/// ?
///
public static event ChatMessage OnChatMessage;
public static void Connected()
{
OnConnection?.Invoke(true, GetPlayerID());
}
public static void Disconnected(string reason)
{
OnConnection?.Invoke(false, GetPlayerID(), reason);
}
public static void Connected(int playerID)
{
OnConnection?.Invoke(true, playerID);
}
public static void Disconnected(int playerID)
{
OnConnection?.Invoke(false, playerID);
}
public static bool ChatMessageReceived(string from, string message)
{
CancelEventArgs args = new CancelEventArgs(false);
OnChatMessage?.Invoke(from, message, args);
return args.Cancel;
}
#endregion
///
/// Send a local chat message to this player
///
/// Username of the player who sent this message
/// The player's message
public static void LocalChatMessage(string from, string message)
{
Main.MainChat.AddMessage(from, message);
}
///
/// Connect to any server
///
/// The server address to connect. Example: 127.0.0.1:4499
public static void Connect(string serverAddress)
{
Networking.ToggleConnection(serverAddress);
}
///
/// ?
///
public static void Disconnect()
{
Networking.ToggleConnection(null);
}
///
/// Check if the player is already on a server
///
public static bool IsOnServer()
{
return Networking.IsOnServer;
}
///
/// Get the local player's ID
///
/// PlayerID
public static int GetPlayerID()
{
return Main.LocalPlayerID;
}
///
/// Check if a RAGECOOP menu is visible
///
public static bool IsMenuVisible()
{
#if NON_INTERACTIVE
return false;
#else
return Menus.CoopMenu.MenuPool.AreAnyVisible;
#endif
}
///
/// Check if the RAGECOOP chat is visible
///
public static bool IsChatFocused()
{
return Main.MainChat.Focused;
}
///
/// Check if the RAGECOOP list of players is visible
///
public static bool IsPlayerListVisible()
{
return Util.GetTickCount64() - PlayerList.Pressed < 5000;
}
///
/// Get the version of RAGECOOP
///
public static string GetCurrentVersion()
{
return Main.CurrentVersion;
}
///
/// Get that player's local username
///
public static string GetUsername()
{
return Main.Settings.Username;
}
///
/// Set a new username for this player
///
/// The new username
/// false if the player already joined a server or the username is null or empty otherwise true
public static bool SetUsername(string username)
{
if (IsOnServer() || string.IsNullOrEmpty(username))
{
return false;
}
Main.Settings.Username = username;
return true;
}
///
/// Get or set the client's settings.
///
/// The client's settings, you should NEVER change settings without notifying the player.
public static Settings Settings()
{
return Main.Settings;
}
}
}