Chat-O-Matic/protocols/irc/IrcProtocol.h

114 lines
2.8 KiB
C
Raw Normal View History

2021-06-20 22:17:24 -05:00
/*
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef _IRC_PROTOCOL_H
#define _IRC_PROTOCOL_H
#include <String.h>
#include <StringList.h>
2021-06-20 22:17:24 -05:00
2021-08-10 00:03:28 -05:00
#include <libsupport/KeyMap.h>
2021-06-20 22:17:24 -05:00
#include <ChatProtocol.h>
2021-08-10 00:03:28 -05:00
typedef KeyMap<BString, BString> StringMap;
class BSocket;
class BDataIO;
2021-08-10 00:03:28 -05:00
2021-06-20 22:17:24 -05:00
class IrcProtocol : public ChatProtocol {
public:
IrcProtocol();
~IrcProtocol();
2021-06-20 22:17:24 -05:00
// ChatProtocol inheritance
virtual status_t Init(ChatProtocolMessengerInterface* interface);
virtual status_t Shutdown();
virtual status_t UpdateSettings(BMessage* settings);
2021-06-20 22:17:24 -05:00
virtual status_t Process(BMessage* msg);
virtual BMessage SettingsTemplate(const char* name);
virtual const char* Signature() const { return "irc"; }
virtual const char* FriendlySignature() const { return "IRC"; }
2021-06-20 22:17:24 -05:00
virtual void SetAddOnPath(BPath path) { fAddOnPath = path; }
virtual BPath AddOnPath() { return fAddOnPath; }
2021-06-20 22:17:24 -05:00
virtual const char* GetName() { return fName; }
virtual void SetName(const char* name) { fName = name; }
2021-06-20 22:17:24 -05:00
virtual ChatProtocolMessengerInterface*
MessengerInterface() const { return fMessenger; }
// IRC
status_t Loop();
BMessage* fSettings;
2021-06-20 22:17:24 -05:00
private:
void _ProcessLine(BString line);
void _ProcessNumeric(int32 numeric, BString sender,
2021-08-09 19:03:37 -05:00
BStringList params);
void _ProcessNumericError(int32 numeric, BString sender,
BStringList params);
void _ProcessCommand(BString command, BString sender,
2021-08-09 19:03:37 -05:00
BStringList params);
2021-08-10 10:00:26 -05:00
void _MakeReady(BString nick, BString ident);
BString _LineSender(BStringList words);
BString _LineCode(BStringList words);
2021-08-09 19:03:37 -05:00
BStringList _LineParameters(BStringList words, BString line);
void _SendMsg(BMessage* msg);
void _SendIrc(BString cmd);
// Used with "nick!ident"-formatted strings
BString _SenderNick(BString sender);
BString _SenderIdent(BString sender);
2021-08-10 00:03:28 -05:00
BString _IdentNick(BString ident);
bool _IsChannelName(BString name);
// Read a data stream until newline found; if data found past
// newline, append to given buffer for later use
BString _ReadUntilNewline(BDataIO* data, BString* extraBuffer);
// Trim given string until newline hit, return trimmed part
BString _TrimStringToNewline(BString* str);
// GUI templates
BMessage _AccountTemplate();
BMessage _RoomTemplate();
BSocket* fSocket;
BString fRemainingBuf;
thread_id fRecvThread;
BString fNick;
2021-08-09 19:03:37 -05:00
const char* fUser;
BString fIdent;
BString fPartText;
2021-06-20 22:17:24 -05:00
// WHOREPLY is requested by the add-on to populate the user-list, but the
// user might also use the /who command― if the user does, this is true
bool fWhoRequested;
bool fWriteLocked;
2021-08-10 00:03:28 -05:00
StringMap fIdentNicks; // User ident → nick
2021-06-20 22:17:24 -05:00
BPath fAddOnPath;
BString fName;
ChatProtocolMessengerInterface* fMessenger;
2021-08-09 19:03:37 -05:00
bool fReady;
2021-06-20 22:17:24 -05:00
};
#endif // _IRC_PROTOCOL_H