Introduction
The new BCDC++
startup.lua v3 creates a totally new Lua interface, which means the old
scripts
are incompatible with the new API (but those which come with the
compiled client are converted). This new interface makes scripting
much more easier, because you can use parametrized functions, and you
can
forget the old setListener calls. In this version, the core calls has
been
binded
to
the Lua API, so their names are the same as in C++, and works in
object-oriented way.
Every value and function is
binded as the field of the dcpp table (namespace). It regards for
enumerations as well: they are directly in the dcpp table, not in the
corresponding manager's subtable. Every loaded script
gets a new, individual
namespace, so global variables won't cause name clashes,
but it's
recommended to use local variables, because they are faster.
Some words about usercommands: dcpp.FavoriteManager.addUserCommand()
registers a Lua usercommand, which - when selected - generates an
OnOwnMessage(hub,message) event, where the hub is the
client object of the hub
we clicked, and the message is the command passed to the call (see
usage). You can use every parameter
which is avaible on the client in the usual way: %[userNI], %[myTA] and
%[hubURL] will work. The only restriction is %[line:] and %[kickline:]
dialogs - they are unavaible and can't be used.
Currently just this kind of
usercommand-handler implemented, but in the future (when
OnPrivateMessageOut will be implemented), the corresponding function
will be called (eg. if the command starts with $To: or BMSG ... PMXXXX
then OnPrivateMessageOut will be called.) If you want to register a
usercommand, put it outside from every function.
When
you save a script, please select a human-readable name, and use just
latin letters and numbers (thus, [a-zA-Z0-9]), and just one point,
before the extension. It's important, else usercommands won't work (Now
the extensionless filename identifies the script's namespace, so points
are disallowed, because it has special meaning in Lua).
Avaible
commands |
/lualist |
Lists the currently loaded scripts |
/luaload <scriptname.lua> |
Loads the given script from the
scripts subdirectory. If script is already loaded, then reloads it. |
/luaunload <scriptname.lua> |
Unloads the given script, but keeps it in the list |
/luaremove <scriptname.lua> |
Unloads & removes the given script from the
list. |
/meminfo |
Shows some information about Lua interface's memory
usage. |
Events
OnConnected(Client
hub)
Called when the client tries to connect to a hub (ie. the frame opens).
OnDisconnected(Client
hub)
Called when the client closes a hub (ie. the frame destroyed).
OnUserConnected(Client
hub,Identity user)
Called when a new user connect to a hub.
OnUserDisconnected(Client
hub,Identity user)
Called when a user logs out from the hub.
OnChatMessage(Client
hub,Identity user, string
text, boolean thirdperson)
Called when a chat message comes from the hub, including Own incoming
messages. If the function returns true, the message won't appear in the
chat.
OnOwnMessage(Client
hub, string text)
Called when enter is pressed in the chat input line. If the function
returns true, the message won't be sent to the hub.
OnPrivateMessageIn(Client
hub,Identity from, Identity to, Identity replyto, string message,
boolean thirdperson)
Called when a private message is received. If function returns true,
then the message won't appear.
OnInfo(Client
hub,Identity user, string
INFO)
Called when a new INFO comes about the user.
OnHubRaw(Client
hub, string command)
Called every time when a protocol command received from the hub. If
returns true, other functions won't be called, and message won't be parsed.
OnRawIn(UserConnection
user, string command)
Called when a Client-To-Client command received. If function returns
true, the client will close the connection.
OnRawOut(UserConnection
user, string command)
Called when a Client-To-Client command goes out. If function returns
true, the client won't send the command.
OnError(string message)
Called when an error occured in the script.
Binded classes in alphabetical order:
ClientManager
void closeClient(hub
hub) - Closes the given hub.
table findHub(string
hubaddress)
- Returns with the hub which
has the given address or URL, or nil, if we aren't connected to it.
table getHubs()
- Return an array with the opened (but even the
not connected) hubs as Client.
table getUsers()
- Returns with an array, where the values have Identity
type.
hub openClient(string
address, string nickname) - Opens a new hub.
FavoriteManager
UserCommand
addUserCommand(number
UCType,
number UCContext, number
UCFlags, string name, string
command, string
hub)
- Adds a new usercommand in the given context. If address is given, it
will appear on that hub (is hub is "op", then on every hub, where you
are operator).
Enumerations:
UCType
SEPARATOR |
Creates a separator |
RAW |
Creates a raw menu |
RAW_ONCE |
Creates a raw menu, but sends once per
nick |
REMOVE |
Removes the given usercommand |
CLEAR |
Removes all usercommand |
UCContext
HUB |
Hub context |
CHAT |
Chat-userlist context |
SEARCH |
Search window context |
FILELIST |
Filelist context |
MASK |
All context |
table getUserCommands() - Return with an array, where the values are the usercommands (both come from the hub, and registered by Lua)
SettingsManager
string get(string
sname) - Return the given string setting from DCPlusPlus.xml.
Text
string acpToUtf8(string
str) - Converts the given string to UTF-8.
boolean isAscii(string
str) - Returns true, if the given string contains just ASCII letters.
table tokenize(string
str, string separator
= " ") - Returns with a table which contains the matches of the text.
If separator is missing, it's default value is a space, therefore it
returns
with the words of the text.
string utf8ToAcp(string
str) - Converts the given string to ACP.
Utils
string
decToIp(number IP)
- Converts the given number to IP address.
string encodeURI(string
aString, boolean reverse = false) - Encodes or decodes
the given URI.
boolean fileExists(string
path) - Returns true if the given file exists.
string formatBytes(number aBytes / string
aBytes) - Formats the given bytes into
human-readable form
(B/Kb/Mb/Gb/Tb/Pb/Eb)
string formatClientType(number ClientType / string ClientType) - Formats the given CT to the corresponding format.
string formatExactSize(number aBytes / string string
aBytes) - Formats the given size to three-digit grouped format like 1 234 567 890
string formatParams(string
format, table o, boolean keep = false)
- Formats the given string
by querying table o for every %[xxx] parameter. Third parameter
controls whether non-existing keys should be removed or not. Useful if
you want to use this call on a string two or three times: first and
second time use this switch, but not on the last call.
string formatSeconds(number aSeconds / string aSeconds, boolean supressHours = false) - Formats the given seconds to MM:SS format, or to HH:MM:SS format, if supressHours is true.
string formatStatus(number StatusFlag) - Formats the status
into string.
string getAppPath() - Returns with the client's main folder.
string getIpCountry(string
IP, boolean fullname = false)
- Return with the two-letter country code of the IP, or with it's full
name, if second parameter is true. Returns N/A if not found (or the
first parameter is not a valid IP address)
number getStartTime()
-
Returns the client's uptime, in seconds.
number
getVersion()
- Gets the given version as a number.
number ipToDec(string
IP) - Converts the given IP address to number. Returns -1 on
failure.
number isIp(string
IP) - Returns the four part of the IP if it's valid, or -1
if isn't.
boolean isPrivateIp(string
/ number
IP) - Returns true if the given IP is private
(10.0.0.0/8;127.0.0.0/8;172.16.0.0/12;192.168.0.0/16)
void sendUDP(string ip_port, string message) - Sends the given message to the given address.
void serialize(string
filename, table/string store, string tablename)
- Saves the given table or string into a file. You can use path as
filename like dcpp.Utils.getAppPath().."scripts\\settings.ini"
function sortByKeys(table
t, boolean descending = false)
- Returns with an iterator function which gives back the key and the
next
value of the given table on each call, where the return values (table's
keys) are sorted in ascended by default,
or descended, if second parameter given. Example: for key, value in
dcpp.Utils.sortByKeys(hash) do ... end.
string validateFileName(string
filename) - Removes the forbidden characters from the given
filename (or rather: from path).
void LogMessage(string message) - Prints the given string to system.log.
Types in alphabetical order:
AdcCommand
This class contains static methods, which are avaible as the fields of
the dcpp.AdcCommand table.
number toSID(string
aSID) - Returns the given SID string as number
string fromSID(number
aSID) - Return the given SID number as string
Client
void addHubLine(string
message)
- Appends the message in the
main chat (but doesn't send it to the hub)
string escape(string
str) - Escapes the given string, depending on the hub's type
(NMDC or ADC)
Identity
findUser(string
aNick / string CID / number sid)
- Returns with the Identity of the user if found, else nil (CID and SID
is ADC only).
string getAddress()
- Returns with the hub's IP/DNS and port
number getAvailable()
- Returns with the currently connected user's full sharesize in bytes.
string getHubName()
- Returns with the hub's name, which goes for the first '-' sign. If
not found, then returns with the URL.
string getHubDescription()
- Returns with the hub's description.
Identity
getHubIdentity()
- Returns the hub identity.
string getHubUrl() -
Returns with the hub's full address with port.
Identity
getMyIdentity()
- Returns with our identity.
number getPort() -
Returns with the port we are connected, as a number.
string getIp() -
Returns with the hub's IP address
number getUserCount()
- Returns the currently connected users to the hub as number.
table getUserList()
-Returns with a table where the keys are the nicknames (NMDC) or SIDs
(ADC) as string,
the values
has Identity
type.
void hubMessage(string
aMessage, boolean
thirdPerson = false) - Sends a chat message to the hub.
boolean isAdc() -
Returns true, if the hub is ADC.
boolean isConnected()
- Returns true, if we are connected to the hub.
boolean isOp() -
Returns true, if we are operator on the hub.
void parseCommand(string
command) - Emulates an incoming command from the hub, and
parses it.
void privateMessage(Identity
ou, string msg,
boolean thirdPerson = false, boolean hideFromSelf = false) -
Sends a private
message to the given
user, and
opens the private frame, if hideFromSelf is true.
void redirect(string
url) - Quits from the current hub, and connects to the new
one in the same frame.
void sendUserCmd(string
aUserCmd) - Sends the
given raw command to the hub.
Identity
string get(string
name) -
Returns with the given field's value as
string.
string getCID() -
Returns with the users CID
Client
getClient()
-
Gets the Identity's Client.
table getParams(string
prefix) - Fills the given table with the
parameters, with the given prefix, for later use
dcpp.Utils.formatParams.
string getSIDString()
- Gets the Identity's
session ID.
StatusFlags
getStatus()
- Gets the Identity's status. Use StatusFlags
enumeration to determine the status.
string getTag() -
Returns with the Identity's tag,
or empty string if
not set.
boolean isAdc() -
Returns true, if the user is on ADC hub.
boolean isClientType(ClientType ct)
-
Returns true, if the Identity is
the given ClientType.
boolean isSet(string
name) -
Returns true, if the given field is set.
void set(string
name, string value)
- Sets the given field to the given
value.
Enumeration:
ClientType
BOT |
Identity is bot |
REGGED |
Identity is registered |
OP |
Identity
is operator |
SU |
Identity
is super-user |
OWNER |
Identity
is owner |
HUB |
Identity
is a hub |
StatusFlags
NORMAL |
Normal user |
AWAY |
User set away mode |
SERVER |
2
hours uptime + 200 MB uploaded |
FIREBALL |
Upload
speed is above 100 Kb/s |
TLS |
Supports
secure data-transfer |
NAT |
Supports NAT traversal |
UserCommand
number getId() -
Returns the ID of the usercommand.
UCType getType()
- Returns with the type of the usercommand.
UCContext
getContext() - Returns with the context of
the usercommand.
string getName() -
Returns with the name of the usercommand.
string getCommand()
- Returns with the command of the usercommand.
string getHub() -
Return with the associated hub's name (might be empty string or "op").
bool isHub() -
Returns true if the command was sent by a hub, or false if a script
registered it.
void remove() - Removes the given usercommand.
UserConnection
void close() -
Closes the current connection (it has the same effect as return
true).
string getIp() -
Return with the IP address of the user in IP:port format.
void send(string
message) - Sends the given message to the peer.
Troubleshooting
If you have any kind of problem or you found a bug, contact me
(Thor).
