1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00

Incomplete implementation of the IRC library.

This commit is contained in:
Sandu Liviu Catalin 2015-10-30 04:17:18 +02:00
parent 6763c41c39
commit f27dea4693
6 changed files with 2267 additions and 15 deletions

View File

@ -5,6 +5,10 @@
// ------------------------------------------------------------------------------------------------
#include <cstdio>
#if defined(_WIN32)
#include <winsock2.h>
#endif // _WIN32
// ------------------------------------------------------------------------------------------------
namespace SqMod {
@ -19,6 +23,10 @@ void BindCallbacks() noexcept;
// ------------------------------------------------------------------------------------------------
SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallbacks * calls, PluginInfo * info)
{
#if defined(_WIN32)
WSADATA wsaData;
#endif // _WIN32
// Verify that core components are working
if (!_Log)
{
puts("[SQMOD] Unable to start because the logging class could not be instantiated");
@ -29,6 +37,14 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallback
puts("[SQMOD] Unable to start because the central core class could not be instantiated");
return SQMOD_FAILURE;
}
#if defined(_WIN32)
// Initialize the sockets on windows
else if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
puts("[SQMOD] Unable to start because the windows sockets could not be initialized");
return SQMOD_FAILURE;
}
#endif // _WIN32
else
{
_Func = funcs;

View File

@ -308,19 +308,21 @@ class LocalEvent;
#define SQMOD_CHBUFBC(n) (n * sizeof(SQChar))
// Short notation for static casting to primitive types
#define _SCI8(v) static_cast<Int8>(v)
#define _SCU8(v) static_cast<Uint8>(v)
#define _SCI16(v) static_cast<Int16>(v)
#define _SCU16(v) static_cast<Uint16>(v)
#define _SCI32(v) static_cast<Int32>(v)
#define _SCU32(v) static_cast<Uint32>(v)
#define _SCI64(v) static_cast<Int64>(v)
#define _SCU64(v) static_cast<Uint64>(v)
#define _SCSQI(v) static_cast<SQInteger>(v)
#define _SCF32(v) static_cast<Float32>(v)
#define _SCF64(v) static_cast<Float64>(v)
#define _SCSQF(v) static_cast<SQFloat>(v)
#define _SCSZT(v) static_cast<size_t>(v)
#define _SCI8(v) static_cast< Int8 >(v)
#define _SCU8(v) static_cast< Uint8 >(v)
#define _SCI16(v) static_cast< Int16 >(v)
#define _SCU16(v) static_cast< Uint16 >(v)
#define _SCI32(v) static_cast< Int32 >(v)
#define _SCU32(v) static_cast< Uint32 >(v)
#define _SCI64(v) static_cast< Int64 >(v)
#define _SCU64(v) static_cast< Uint64 >(v)
#define _SCSQI(v) static_cast< SQInteger >(v)
#define _SCF32(v) static_cast< Float32 >(v)
#define _SCF64(v) static_cast< Float64 >(v)
#define _SCSQF(v) static_cast< SQFloat >(v)
#define _SCSZT(v) static_cast< size_t >(v)
#define _SCSS(v) static_cast< SQChar * >(v)
#define _SCSCS(v) static_cast< const SQChar * >(v)
// Short notation for getting the minimum and maxmimum value of primitives
#define _NLMIN(t) std::numeric_limits<t>::min()

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,660 @@
#ifndef _LIBRARY_IRC_SESSION_HPP_
#define _LIBRARY_IRC_SESSION_HPP_
// ------------------------------------------------------------------------------------------------
#include "Common.hpp"
// ------------------------------------------------------------------------------------------------
#include <libircclient.h>
#include <libirc_rfcnumeric.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
namespace IRC {
/* ------------------------------------------------------------------------------------------------
* ...
*/
class Session
{
protected:
/* --------------------------------------------------------------------------------------------
* ...
*/
static irc_callbacks_t s_Callbacks;
/* --------------------------------------------------------------------------------------------
* ...
*/
static bool s_Initialized;
/* --------------------------------------------------------------------------------------------
* ...
*/
static irc_callbacks_t * GetCallbacks() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
static void ForwardEvent(Function & listener, const char * event, const char * origin, const char ** params, unsigned int count) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
static void ForwardEvent(Function & listener, unsigned int event, const char * origin, const char ** params, unsigned int count) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
static void ForwardEvent(Function & listener, const char * nick, const char * addr, irc_dcc_t dccid) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
static void ForwardEvent(Function & listener, const char * nick, const char * addr, const char * filename, unsigned long size, irc_dcc_t dccid) noexcept;
public:
/* --------------------------------------------------------------------------------------------
* ...
*/
Session() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Session(const Session & o) = delete;
/* --------------------------------------------------------------------------------------------
* ...
*/
Session(Session && o) = delete;
/* --------------------------------------------------------------------------------------------
* ...
*/
~Session();
/* --------------------------------------------------------------------------------------------
* ...
*/
Session & operator = (const Session & o) = delete;
/* --------------------------------------------------------------------------------------------
* ...
*/
Session & operator = (Session && o) = delete;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 Cmp(const Session & o) const noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
const SQChar * ToString() const noexcept;
/* --------------------------------------------------------------------------------------------
* Retrieve the local tag.
*/
const SQChar * GetTag() const noexcept;
/* --------------------------------------------------------------------------------------------
* Change the local tag.
*/
void SetTag(const SQChar * tag) noexcept;
/* --------------------------------------------------------------------------------------------
* Retrieve the local data.
*/
SqObj & GetData() noexcept;
/* --------------------------------------------------------------------------------------------
* Change the local data.
*/
void SetData(SqObj & data) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnConnect() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnConnect(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnNick() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnNick(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnQuit() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnQuit(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnJoin() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnJoin(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnPart() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnPart(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnMode() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnMode(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnUmode() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnUmode(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnTopic() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnTopic(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnKick() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnKick(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnChannel() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnChannel(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnPrivMSG() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnPrivMSG(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnNotice() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnNotice(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnChannel_Notice() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnChannel_Notice(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnInvite() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnInvite(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnCTCP_Req() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnCTCP_Req(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnCTCP_Rep() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnCTCP_Rep(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnCTCP_Action() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnCTCP_Action(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnUnknown() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnUnknown(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnNumeric() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnNumeric(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnDcc_Chat_Req() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnDcc_Chat_Req(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
Function & GetOnDcc_Send_Req() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnDcc_Send_Req(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool IsValid() const noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 Connect(const SQChar * server, SQUint32 port, const SQChar * nick) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 Connect(const SQChar * server, SQUint32 port, const SQChar * nick, const SQChar * passwd) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 Connect(const SQChar * server, SQUint32 port, const SQChar * nick, const SQChar * passwd,
const SQChar * username) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 Connect(const SQChar * server, SQUint32 port, const SQChar * nick, const SQChar * passwd,
const SQChar * username, const SQChar * realname) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 Connect6(const SQChar * server, SQUint32 port, const SQChar * nick) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 Connect6(const SQChar * server, SQUint32 port, const SQChar * nick, const SQChar * passwd) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 Connect6(const SQChar * server, SQUint32 port, const SQChar * nick, const SQChar * passwd,
const SQChar * username) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 Connect6(const SQChar * server, SQUint32 port, const SQChar * nick, const SQChar * passwd,
const SQChar * username, const SQChar * realname) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void Disconnect() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
bool IsConnected() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdJoin(const SQChar * channel) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdJoin(const SQChar * channel, const SQChar * key) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdPart(const SQChar * channel) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdInvite(const SQChar * nick, const SQChar * channel) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdNames(const SQChar * channel) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdList() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdList(const SQChar * channel) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdTopic(const SQChar * channel) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdTopic(const SQChar * channel, const SQChar * topic) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdChannelMode(const SQChar * channel) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdChannelMode(const SQChar * channel, const SQChar * mode) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdUserMode() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdUserMode(const SQChar * mode) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdKick(const SQChar * nick, const SQChar * channel) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdKick(const SQChar * nick, const SQChar * channel, const SQChar * reason) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdMsg(const SQChar * nch, const SQChar * text) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdMe(const SQChar * nch, const SQChar * text) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdNotice(const SQChar * nch, const SQChar * text) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdCtcpRequest(const SQChar * nick, const SQChar * request) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdCtcpReply(const SQChar * nick, const SQChar * reply) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdNick(const SQChar * nick) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdWhois(const SQChar * nick) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdQuit() noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 CmdQuit(const SQChar * reason) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
SQInt32 SendRaw(const SQChar * str) noexcept;
private:
/* --------------------------------------------------------------------------------------------
* ...
*/
irc_session_t* m_Session;
// --------------------------------------------------------------------------------------------
Function m_OnConnect;
Function m_OnNick;
Function m_OnQuit;
Function m_OnJoin;
Function m_OnPart;
Function m_OnMode;
Function m_OnUmode;
Function m_OnTopic;
Function m_OnKick;
Function m_OnChannel;
Function m_OnPrivMSG;
Function m_OnNotice;
Function m_OnChannel_Notice;
Function m_OnInvite;
Function m_OnCTCP_Req;
Function m_OnCTCP_Rep;
Function m_OnCTCP_Action;
Function m_OnUnknown;
Function m_OnNumeric;
Function m_OnDcc_Chat_Req;
Function m_OnDcc_Send_Req;
// --------------------------------------------------------------------------------------------
String m_Tag;
SqObj m_Data;
public:
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnConnect(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnNick(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnQuit(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnJoin(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnPart(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnMode(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnUmode(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnTopic(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnKick(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnChannel(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnPrivMSG(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnNotice(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnChannel_Notice(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnInvite(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnCTCP_Req(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnCTCP_Rep(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnCTCP_Action(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnUnknown(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnNumeric(irc_session_t * session, unsigned int event, const char * origin, const char ** params, unsigned int count);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnDcc_Chat_Req(irc_session_t * session, const char * nick, const char * addr, irc_dcc_t dccid);
/* --------------------------------------------------------------------------------------------
* ...
*/
static void OnDcc_Send_Req(irc_session_t * session, const char * nick, const char * addr, const char * filename, unsigned long size, irc_dcc_t dccid);
};
} // Namespace:: IRC
} // Namespace:: SqMod
#endif // _LIBRARY_IRC_SESSION_HPP_

View File

@ -40,10 +40,10 @@ bool RegisterAPI(HSQUIRRELVM vm) noexcept
_Log->cFtl(!Register_CVehicle(vm), "Unable to register: Vehicle") || \
_Log->cFtl(!Register_Entity(vm), "Unable to register: Entity") || \
_Log->cFtl(!Register_CFG(vm), "Unable to register: CFG") || \
_Log->cFtl(!Register_Datetime(vm), "Unable to register: Datetime") || \
_Log->cFtl(!Register_FileIO(vm), "Unable to register: FileIO") || \
_Log->cFtl(!Register_Format(vm), "Unable to register: Format") || \
_Log->cFtl(!Register_IRC(vm), "Unable to register: IRC") || \
_Log->cFtl(!Register_INI(vm), "Unable to register: INI") || \
_Log->cFtl(!Register_JSON(vm), "Unable to register: JSON") || \
_Log->cFtl(!Register_LongInt(vm), "Unable to register: LongInt") || \

View File

@ -41,10 +41,10 @@ bool Register_CVehicle(HSQUIRRELVM vm);
bool Register_Entity(HSQUIRRELVM vm);
// ------------------------------------------------------------------------------------------------
bool Register_CFG(HSQUIRRELVM vm);
bool Register_Datetime(HSQUIRRELVM vm);
bool Register_FileIO(HSQUIRRELVM vm);
bool Register_Format(HSQUIRRELVM vm);
bool Register_IRC(HSQUIRRELVM vm);
bool Register_INI(HSQUIRRELVM vm);
bool Register_JSON(HSQUIRRELVM vm);
bool Register_LongInt(HSQUIRRELVM vm);