//Copyright (c) 2007 Joshua R. Rodgers
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace Bone
{
partial class Handle
{
///
/// Adds a contact to the internal contact list.
///
/// Name of the contact.
/// true on failure.
public bool AddContact(string contact)
{
return Importer.bone_addcontact(bHandle, contact);
}
///
/// Requests an email change.
/// Causes disconnection and a new password is sent to verify the e-mail.
///
/// The email address to change to.
/// true on failure.
public bool ChangeEmail(string newEmail)
{
return Importer.bone_changeemail(bHandle, newEmail);
}
///
/// Creates a new user using the name and email provided.
///
/// The name of the user to create.
/// Email address to send the password to.
/// true on failure.
public bool CreateUser(string user, string email)
{
if (Utility.handleDictionary.ContainsKey(bHandle))
Utility.handleDictionary.Remove(bHandle);
bHandle = Importer.bone_create();
Utility.handleDictionary.Add(bHandle, this);
return Importer.bone_createuser(bHandle, user, email);
}
///
/// Removes a contact from the internal contacts list.
///
/// Name of the contact.
/// true on failure.
public bool DeleteContact(string contact)
{
return Importer.bone_delcontact(bHandle, contact);
}
///
/// Invites a user to the specified channel.
///
/// Name of the channel to invite the user to.
/// Name of the user to invite to the channel.
/// true on failure.
public bool InviteUser(string channelName, string name)
{
return Importer.bone_inviteuser(bHandle, channelName, name);
}
///
/// Determines wheter or not if a user is online.
///
/// Name of the user to check the online status of.
/// true on failure.
public bool IsOnline(string name)
{
return Importer.bone_isonline(bHandle, name);
}
///
/// Causes the current Handle to join the specified channel.
///
/// Name of the channel to join.
/// true on failure.
public bool JoinChannel(string channelName)
{
return Importer.bone_joinchannel(bHandle, channelName, 0, "");
}
///
/// Causes the current Handle to join the specified channel.
///
/// Name of the channel to join,
/// Password to use when joining the channel.
/// true on failure.
public bool JoinChannel(string channelName, string password)
{
return Importer.bone_joinchannel(bHandle, channelName, 0, password);
}
///
/// Causes the current Handle to join the specified channel.
///
/// Name of the channel to join,
/// Specifies if this channel is invite only.
/// true on failure.
public bool JoinChannel(string channelName, bool inviteOnly)
{
return Importer.bone_joinchannel(bHandle, channelName, (inviteOnly ? 1 : 0), "");
}
///
/// Causes the current Handle to leave the specified channel.
///
/// Name of the channel to leave
/// true on failure.
public bool LeaveChannel(string channelName)
{
return Importer.bone_leavechannel(bHandle, channelName);
}
///
/// Logs the current handle into the server for normal operation.
///
/// User name to use when logging in.
/// Password to use when logging in.
/// true on failure.
public bool Login(string user, string password)
{
if (Utility.handleDictionary.ContainsKey(bHandle))
Utility.handleDictionary.Remove(bHandle);
bHandle = Importer.bone_create();
Utility.handleDictionary.Add(bHandle, this);
return Importer.bone_login(bHandle, user, password);
}
///
/// Modifies the user's profile.
///
/// Name of the user to modify.
/// New password.
/// New email address.
/// Type of the user.
/// Enable/Disable the user.
/// true on failure.
public bool ModifyUserProfile(string user, string password, string email, int userType, int isDisabled)
{
return Importer.bone_modifyuserprofile(bHandle, user, password, email, userType, isDisabled);
}
///
/// Pings the specified user.
///
/// Name of the user to ping.
/// true on failure.
public bool PingUser(string user)
{
return Importer.bone_pinguser(bHandle, user);
}
///
/// Requests a list of channels.
///
/// true on failure.
public bool RequestChannelList()
{
return Importer.bone_reqchannellist(bHandle);
}
///
/// Requests the password of a user.
///
/// User name to request password of.
/// Email of the user.
///
public bool RequestPassword(string user, string email)
{
if (Utility.handleDictionary.ContainsKey(bHandle))
Utility.handleDictionary.Remove(bHandle);
bHandle = Importer.bone_create();
Utility.handleDictionary.Add(bHandle, this);
return Importer.bone_reqpassword(bHandle, user, email);
}
///
/// Requests a profile about a user.
///
/// Name of the user.
/// true on failure.
public bool ReqestUserProfile(string user)
{
return Importer.bone_requserprofile(bHandle, user);
}
///
/// Sends a text message to the specified target.
///
/// Target (user or channel) to send the message to.
/// Message to be sent.
/// true on failure.
public bool SendText(string target, string message)
{
return Importer.bone_sendtext(bHandle, target, message);
}
///
/// Sends a text message to the specified target.
///
/// Target (user or channel) to send the message to.
/// Message to be sent.
/// Variable number of arguments to be used by the format string.
/// true on failure.
public bool SendText(string target, string format, params object[] args)
{
StringBuilder strBuilder = new StringBuilder();
strBuilder.AppendFormat(format, args);
return Importer.bone_sendtext(bHandle, target, strBuilder.ToString());
}
///
/// Requests an update to the contacts list stored internally.
///
/// true on failure.
public bool UpdateContacts()
{
return Importer.bone_updatecontacts(bHandle);
}
///
/// Disconnects the current handle from the server.
///
/// true on failure.
public bool Disconnect()
{
return Importer.bone_destroy(bHandle);
}
}
}