/*
TShock, a server mod for Terraria
Copyright (C) 2011-2017 Nyx Studios (fka. The TShock Team)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
using System.Collections.Generic;
using System.ComponentModel;
using TShockAPI.DB;
namespace TShockAPI.Hooks
{
///
/// EventArgs used for the event.
///
public class PlayerPostLoginEventArgs
{
///
/// The player who fired the event.
///
public TSPlayer Player { get; set; }
///
/// Initializes a new instance of the PlayerPostLoginEventArgs class.
///
/// The player who fired the event.
public PlayerPostLoginEventArgs(TSPlayer ply)
{
Player = ply;
}
}
///
/// EventArgs used for the event.
///
public class PlayerPreLoginEventArgs : HandledEventArgs
{
///
/// The player who fired the event.
///
public TSPlayer Player { get; set; }
///
/// The player's login name.
///
public string LoginName { get; set; }
///
/// The player's raw password.
///
public string Password { get; set; }
}
///
/// EventArgs used for the event.
///
public class PlayerLogoutEventArgs
{
///
/// The player who fired the event.
///
public TSPlayer Player { get; set; }
///
/// Initializes a new instance of the PlayerLogoutEventArgs class.
///
/// The player who fired the event.
public PlayerLogoutEventArgs(TSPlayer player)
{
Player = player;
}
}
///
/// EventArgs used for the event.
///
public class PlayerCommandEventArgs : HandledEventArgs
{
///
/// The player who fired the event.
///
public TSPlayer Player { get; set; }
///
/// The command's name that follows the .
///
public string CommandName { get; set; }
///
/// The command's full text.
///
public string CommandText { get; set; }
///
/// The command's parameters extracted from .
///
public List Parameters { get; set; }
///
/// The full list of server commands.
///
public IEnumerable CommandList { get; set; }
///
/// The prefix used to send the command (either or ).
///
public string CommandPrefix { get; set; }
}
///
/// EventArgs used for the event.
///
public class PlayerChatEventArgs : HandledEventArgs
{
///
/// The player who fired the event.
///
public TSPlayer Player { get; set; }
///
/// The raw chat text as received by the server.
///
public string RawText { get; set; }
///
/// The string after being formatted by TShock as specified in the config file.
///
public string TShockFormattedText { get; set; }
}
///
/// EventArgs used for the event.
///
public class PlayerPermissionEventArgs
{
///
/// The player who fired the event.
///
public TSPlayer Player { get; set; }
///
/// The permission being checked.
///
public string Permission { get; set; }
///
/// of the hook.
///
public PermissionHookResult Result { get; set; }
///
/// Initializes a new instance of the PlayerPermissionEventArgs class.
///
/// The player who fired the event.
/// The permission being checked.
public PlayerPermissionEventArgs(TSPlayer player, string permission)
{
Player = player;
Permission = permission;
Result = PermissionHookResult.Unhandled;
}
}
///
/// EventArgs used for the event.
///
public class PlayerItembanPermissionEventArgs
{
///
/// The player who fired the event.
///
public TSPlayer Player { get; set; }
///
/// The banned item being checked.
///
public ItemBan BannedItem { get; set; }
///
/// of the hook.
///
public PermissionHookResult Result { get; set; }
///
/// Initializes a new instance of the PlayerItembanPermissionEventArgs class.
///
/// The player who fired the event.
/// The banned item being checked.
public PlayerItembanPermissionEventArgs(TSPlayer player, ItemBan bannedItem)
{
Player = player;
BannedItem = bannedItem;
Result = PermissionHookResult.Unhandled;
}
}
///
/// EventArgs used for the event.
///
public class PlayerProjbanPermissionEventArgs
{
///
/// The player who fired the event.
///
public TSPlayer Player { get; set; }
///
/// The banned projectile being checked.
///
public ProjectileBan BannedProjectile { get; set; }
///
/// of the hook.
///
public PermissionHookResult Result { get; set; }
///
/// Initializes a new instance of the PlayerProjbanPermissionEventArgs class.
///
/// The player who fired the event.
/// The banned projectile being checked.
public PlayerProjbanPermissionEventArgs(TSPlayer player, ProjectileBan checkedProjectile)
{
Player = player;
BannedProjectile = checkedProjectile;
Result = PermissionHookResult.Unhandled;
}
}
///
/// EventArgs used for the event.
///
public class PlayerTilebanPermissionEventArgs
{
///
/// The player who fired the event.
///
public TSPlayer Player { get; set; }
///
/// The banned tile being checked.
///
public TileBan BannedTile { get; set; }
///
/// of the hook.
///
public PermissionHookResult Result { get; set; }
///
/// Initializes a new instance of the PlayerTilebanPermissionEventArgs class.
///
/// The player who fired the event.
/// The banned tile being checked.
public PlayerTilebanPermissionEventArgs(TSPlayer player, TileBan checkedTile)
{
Player = player;
BannedTile = checkedTile;
Result = PermissionHookResult.Unhandled;
}
}
///
/// A collection of events fired by players that can be hooked to.
///
public static class PlayerHooks
{
///
/// The delegate of the event.
///
/// The EventArgs for this event.
public delegate void PlayerPostLoginD(PlayerPostLoginEventArgs e);
///
/// Fired by players after they've successfully logged in to a user account.
///
public static event PlayerPostLoginD PlayerPostLogin;
///
/// The delegate of the event.
///
/// The EventArgs for this event.
public delegate void PlayerPreLoginD(PlayerPreLoginEventArgs e);
///
/// Fired by players when sending login credentials to the server.
///
public static event PlayerPreLoginD PlayerPreLogin;
///
/// The delegate of the event.
///
/// The EventArgs for this event.
public delegate void PlayerLogoutD(PlayerLogoutEventArgs e);
///
/// Fired by players upon logging out from a user account.
///
public static event PlayerLogoutD PlayerLogout;
///
/// The delegate of the event.
///
/// The EventArgs for this event.
public delegate void PlayerCommandD(PlayerCommandEventArgs e);
///
/// Fired by players when using a command.
///
public static event PlayerCommandD PlayerCommand;
///
/// The delegate of the event.
///
/// The EventArgs for this event.
public delegate void PlayerChatD(PlayerChatEventArgs e);
///
/// Fired by players when they send a chat message packet to the server
/// and before it is transmitted to the rest of the players.
///
public static event PlayerChatD PlayerChat;
///
/// The delegate of the event.
///
/// The EventArgs for this event.
public delegate void PlayerPermissionD(PlayerPermissionEventArgs e);
///
/// Fired by players every time a permission check involving them occurs.
///
public static event PlayerPermissionD PlayerPermission;
///
/// The delegate of the event.
///
/// The EventArgs for this event.
public delegate void PlayerItembanPermissionD(PlayerItembanPermissionEventArgs e);
///
/// Fired by players every time a permission check on banned items involving them occurs.
///
public static event PlayerItembanPermissionD PlayerItembanPermission;
///
/// The delegate of the event.
///
/// The EventArgs for this event.
public delegate void PlayerProjbanPermissionD(PlayerProjbanPermissionEventArgs e);
///
/// Fired by players every time a permission check on banned projectiles involving them occurs.
///
public static event PlayerProjbanPermissionD PlayerProjbanPermission;
///
/// The delegate of the event.
///
/// The EventArgs for this event.
public delegate void PlayerTilebanPermissionD(PlayerTilebanPermissionEventArgs e);
///
/// Fired by players every time a permission check on banned tiles involving them occurs.
///
public static event PlayerTilebanPermissionD PlayerTilebanPermission;
///
/// Fires the event.
///
/// The player firing the event.
public static void OnPlayerPostLogin(TSPlayer ply)
{
if (PlayerPostLogin == null)
{
return;
}
PlayerPostLoginEventArgs args = new PlayerPostLoginEventArgs(ply);
PlayerPostLogin(args);
}
///
/// Fires the event.
///
/// The player firing the event.
/// The command name.
/// The raw command text.
/// The command args extracted from the command text.
/// The list of commands.
/// The command specifier used.
/// True if the event has been handled.
public static bool OnPlayerCommand(TSPlayer player, string cmdName, string cmdText, List args, ref IEnumerable commands, string cmdPrefix)
{
if (PlayerCommand == null)
{
return false;
}
PlayerCommandEventArgs playerCommandEventArgs = new PlayerCommandEventArgs()
{
Player = player,
CommandName = cmdName,
CommandText = cmdText,
Parameters = args,
CommandList = commands,
CommandPrefix = cmdPrefix,
};
PlayerCommand(playerCommandEventArgs);
return playerCommandEventArgs.Handled;
}
///
/// Fires the event.
///
/// The player firing the event.
/// The user name.
/// The password.
/// True if the event has been handled.
public static bool OnPlayerPreLogin(TSPlayer ply, string name, string pass)
{
if (PlayerPreLogin == null)
return false;
var args = new PlayerPreLoginEventArgs {Player = ply, LoginName = name, Password = pass};
PlayerPreLogin(args);
return args.Handled;
}
///
/// Fires the event.
///
/// The player firing the event.
public static void OnPlayerLogout(TSPlayer ply)
{
if (PlayerLogout == null)
return;
var args = new PlayerLogoutEventArgs(ply);
PlayerLogout(args);
}
///
/// Fires the event.
///
/// The player firing the event.
/// The raw chat text sent by the player.
/// The chat text after being formatted.
public static void OnPlayerChat(TSPlayer ply, string rawtext, ref string tshockText)
{
if (PlayerChat == null)
return;
var args = new PlayerChatEventArgs {Player = ply, RawText = rawtext, TShockFormattedText = tshockText};
PlayerChat(args);
tshockText = args.TShockFormattedText;
}
///
/// Fires the event.
///
/// The player firing the event.
/// Event result if the event has been handled, otherwise .
public static PermissionHookResult OnPlayerPermission(TSPlayer player, string permission)
{
if (PlayerPermission == null)
return PermissionHookResult.Unhandled;
var args = new PlayerPermissionEventArgs(player, permission);
PlayerPermission(args);
return args.Result;
}
///
/// Fires the event.
///
/// The player firing the event.
/// Event result if the event has been handled, otherwise .
public static PermissionHookResult OnPlayerItembanPermission(TSPlayer player, ItemBan bannedItem)
{
if (PlayerItembanPermission == null)
return PermissionHookResult.Unhandled;
var args = new PlayerItembanPermissionEventArgs(player, bannedItem);
PlayerItembanPermission(args);
return args.Result;
}
///
/// Fires the event.
///
/// The player firing the event.
/// Event result if the event has been handled, otherwise .
public static PermissionHookResult OnPlayerProjbanPermission(TSPlayer player, ProjectileBan bannedProj)
{
if (PlayerProjbanPermission == null)
return PermissionHookResult.Unhandled;
var args = new PlayerProjbanPermissionEventArgs(player, bannedProj);
PlayerProjbanPermission(args);
return args.Result;
}
///
/// Fires the event.
///
/// The player firing the event.
/// Event result if the event has been handled, otherwise .
public static PermissionHookResult OnPlayerTilebanPermission(TSPlayer player, TileBan bannedTile)
{
if (PlayerTilebanPermission == null)
return PermissionHookResult.Unhandled;
var args = new PlayerTilebanPermissionEventArgs(player, bannedTile);
PlayerTilebanPermission(args);
return args.Result;
}
}
///
/// Defines the possible outcomes of handlers.
///
public enum PermissionHookResult
{
/// Hook doesn't return a result on the permission check.
Unhandled,
/// Permission is explicitly denied by a hook.
Denied,
/// Permission is explicitly granted by a hook.
Granted
}
}