2016-02-27 10:57:10 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Common.hpp"
|
|
|
|
|
2016-02-28 15:17:59 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-06-03 20:27:53 +02:00
|
|
|
#include <cstdlib>
|
2016-02-27 10:57:10 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-02-28 15:17:59 +01:00
|
|
|
namespace SqMod {
|
2016-02-27 10:57:10 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-06-03 20:27:53 +02:00
|
|
|
SQInteger GetNick(HSQUIRRELVM vm)
|
2016-02-28 15:17:59 +01:00
|
|
|
{
|
2016-06-03 20:27:53 +02:00
|
|
|
// Attempt to retrieve the value from the stack as a string
|
|
|
|
StackStrF val(vm, 2);
|
|
|
|
// Have we failed to retrieve the string?
|
|
|
|
if (SQ_FAILED(val.mRes))
|
2016-04-02 11:49:32 +02:00
|
|
|
{
|
2016-06-03 20:27:53 +02:00
|
|
|
return val.mRes; // Propagate the error!
|
2016-04-02 11:49:32 +02:00
|
|
|
}
|
2016-06-03 20:27:53 +02:00
|
|
|
// Attempt to retrieve the nickname
|
|
|
|
irc_target_get_nick(val.mPtr, GetTempBuff(), GetTempBuffSize());
|
|
|
|
// Push the resulted value on the stack
|
|
|
|
sq_pushstring(vm, GetTempBuff(), -1);
|
|
|
|
// Specify that this function returned a value
|
|
|
|
return 1;
|
2016-02-28 15:17:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-06-03 20:27:53 +02:00
|
|
|
SQInteger GetHost(HSQUIRRELVM vm)
|
2016-02-28 15:17:59 +01:00
|
|
|
{
|
2016-06-03 20:27:53 +02:00
|
|
|
// Attempt to retrieve the value from the stack as a string
|
|
|
|
StackStrF val(vm, 2);
|
|
|
|
// Have we failed to retrieve the string?
|
|
|
|
if (SQ_FAILED(val.mRes))
|
2016-04-02 11:49:32 +02:00
|
|
|
{
|
2016-06-03 20:27:53 +02:00
|
|
|
return val.mRes; // Propagate the error!
|
2016-04-02 11:49:32 +02:00
|
|
|
}
|
2016-06-03 20:27:53 +02:00
|
|
|
// Attempt to retrieve the host
|
|
|
|
irc_target_get_host(val.mPtr, GetTempBuff(), GetTempBuffSize());
|
|
|
|
// Push the resulted value on the stack
|
|
|
|
sq_pushstring(vm, GetTempBuff(), -1);
|
|
|
|
// Specify that this function returned a value
|
|
|
|
return 1;
|
2016-02-28 15:17:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-06-03 20:27:53 +02:00
|
|
|
SQInteger StripColorFromMIRC(HSQUIRRELVM vm)
|
2016-04-02 11:49:32 +02:00
|
|
|
{
|
2016-06-03 20:27:53 +02:00
|
|
|
// Attempt to retrieve the value from the stack as a string
|
|
|
|
StackStrF val(vm, 2);
|
|
|
|
// Have we failed to retrieve the string?
|
|
|
|
if (SQ_FAILED(val.mRes))
|
2016-04-02 11:49:32 +02:00
|
|
|
{
|
2016-06-03 20:27:53 +02:00
|
|
|
return val.mRes; // Propagate the error!
|
2016-04-02 11:49:32 +02:00
|
|
|
}
|
2016-06-03 20:27:53 +02:00
|
|
|
// Attempt to strip the colors
|
|
|
|
CStr str = irc_color_strip_from_mirc(val.mPtr);
|
|
|
|
// Could the IRC library allocate memory?
|
|
|
|
if (!str)
|
2016-04-02 11:49:32 +02:00
|
|
|
{
|
2016-06-03 20:27:53 +02:00
|
|
|
return sq_throwerror(vm, _SC("Unable to allocate memory"));
|
2016-04-02 11:49:32 +02:00
|
|
|
}
|
2016-06-03 20:27:53 +02:00
|
|
|
// Push the resulted value on the stack
|
|
|
|
sq_pushstring(vm, str, -1);
|
|
|
|
// Free the memory allocated by the IRC library
|
|
|
|
std::free(str);
|
|
|
|
// Specify that this function returned a value
|
|
|
|
return 1;
|
2016-04-02 11:49:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-06-03 20:27:53 +02:00
|
|
|
SQInteger ConvertColorFromMIRC(HSQUIRRELVM vm)
|
2016-04-02 11:49:32 +02:00
|
|
|
{
|
2016-06-03 20:27:53 +02:00
|
|
|
// Attempt to retrieve the value from the stack as a string
|
|
|
|
StackStrF val(vm, 2);
|
|
|
|
// Have we failed to retrieve the string?
|
|
|
|
if (SQ_FAILED(val.mRes))
|
2016-04-02 11:49:32 +02:00
|
|
|
{
|
2016-06-03 20:27:53 +02:00
|
|
|
return val.mRes; // Propagate the error!
|
2016-04-02 11:49:32 +02:00
|
|
|
}
|
2016-06-03 20:27:53 +02:00
|
|
|
// Attempt to convert the colors
|
|
|
|
CStr str = irc_color_convert_from_mirc(val.mPtr);
|
|
|
|
// Could the IRC library allocate memory?
|
|
|
|
if (!str)
|
|
|
|
{
|
|
|
|
return sq_throwerror(vm, _SC("Unable to allocate memory"));
|
|
|
|
}
|
|
|
|
// Push the resulted value on the stack
|
|
|
|
sq_pushstring(vm, str, -1);
|
|
|
|
// Free the memory allocated by the IRC library
|
|
|
|
std::free(str);
|
|
|
|
// Specify that this function returned a value
|
|
|
|
return 1;
|
2016-04-02 11:49:32 +02:00
|
|
|
}
|
|
|
|
|
2016-05-24 20:36:02 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-06-03 20:27:53 +02:00
|
|
|
SQInteger ConvertColorToMIRC(HSQUIRRELVM vm)
|
2016-02-27 10:57:10 +01:00
|
|
|
{
|
2016-06-03 20:27:53 +02:00
|
|
|
// Attempt to retrieve the value from the stack as a string
|
|
|
|
StackStrF val(vm, 2);
|
|
|
|
// Have we failed to retrieve the string?
|
|
|
|
if (SQ_FAILED(val.mRes))
|
|
|
|
{
|
|
|
|
return val.mRes; // Propagate the error!
|
|
|
|
}
|
|
|
|
// Attempt to convert the colors
|
|
|
|
CStr str = irc_color_convert_to_mirc(val.mPtr);
|
|
|
|
// Could the IRC library allocate memory?
|
|
|
|
if (!str)
|
|
|
|
{
|
|
|
|
return sq_throwerror(vm, _SC("Unable to allocate memory"));
|
|
|
|
}
|
|
|
|
// Push the resulted value on the stack
|
|
|
|
sq_pushstring(vm, str, -1);
|
|
|
|
// Free the memory allocated by the IRC library
|
|
|
|
std::free(str);
|
|
|
|
// Specify that this function returned a value
|
|
|
|
return 1;
|
2016-02-27 10:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|