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>
|
2021-08-09 14:06:04 -05:00
|
|
|
|
#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-16 16:11:37 -05:00
|
|
|
|
#include "IrcConstants.h"
|
|
|
|
|
|
2021-08-10 00:03:28 -05:00
|
|
|
|
|
|
|
|
|
typedef KeyMap<BString, BString> StringMap;
|
|
|
|
|
|
|
|
|
|
|
2021-08-09 14:06:04 -05:00
|
|
|
|
class BSocket;
|
|
|
|
|
class BDataIO;
|
2021-06-21 01:54:42 -05:00
|
|
|
|
|
2021-08-10 00:03:28 -05:00
|
|
|
|
|
2021-06-20 22:17:24 -05:00
|
|
|
|
class IrcProtocol : public ChatProtocol {
|
|
|
|
|
public:
|
|
|
|
|
IrcProtocol();
|
2021-08-09 14:06:04 -05:00
|
|
|
|
~IrcProtocol();
|
2021-06-20 22:17:24 -05:00
|
|
|
|
|
|
|
|
|
// ChatProtocol inheritance
|
|
|
|
|
virtual status_t Init(ChatProtocolMessengerInterface* interface);
|
|
|
|
|
virtual status_t Shutdown();
|
|
|
|
|
|
2021-08-09 14:06:04 -05:00
|
|
|
|
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);
|
2021-08-16 01:25:30 -05:00
|
|
|
|
virtual BObjectList<BMessage>
|
|
|
|
|
Commands();
|
2021-06-20 22:17:24 -05:00
|
|
|
|
|
2021-08-09 14:06:04 -05:00
|
|
|
|
virtual const char* Signature() const { return "irc"; }
|
|
|
|
|
virtual const char* FriendlySignature() const { return "IRC"; }
|
2021-06-20 22:17:24 -05:00
|
|
|
|
|
2021-08-11 17:40:03 -05:00
|
|
|
|
virtual BBitmap* Icon() const;
|
|
|
|
|
|
2021-08-09 14:06:04 -05:00
|
|
|
|
virtual void SetAddOnPath(BPath path) { fAddOnPath = path; }
|
|
|
|
|
virtual BPath AddOnPath() { return fAddOnPath; }
|
2021-06-20 22:17:24 -05:00
|
|
|
|
|
2021-08-09 14:06:04 -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*
|
2021-08-09 14:06:04 -05:00
|
|
|
|
MessengerInterface() const { return fMessenger; }
|
|
|
|
|
|
2021-06-21 01:54:42 -05:00
|
|
|
|
// IRC
|
2021-08-13 14:32:46 -05:00
|
|
|
|
status_t Connect();
|
2021-08-09 14:06:04 -05:00
|
|
|
|
status_t Loop();
|
|
|
|
|
|
2021-06-21 01:54:42 -05:00
|
|
|
|
BMessage* fSettings;
|
2021-06-20 22:17:24 -05:00
|
|
|
|
|
|
|
|
|
private:
|
2021-08-09 14:06:04 -05:00
|
|
|
|
void _ProcessLine(BString line);
|
|
|
|
|
void _ProcessNumeric(int32 numeric, BString sender,
|
2021-08-12 10:14:46 -05:00
|
|
|
|
BStringList params, BString line);
|
2021-08-09 19:03:37 -05:00
|
|
|
|
void _ProcessNumericError(int32 numeric, BString sender,
|
2021-08-12 10:14:46 -05:00
|
|
|
|
BStringList params, BString line);
|
2021-08-09 14:06:04 -05:00
|
|
|
|
void _ProcessCommand(BString command, BString sender,
|
2021-08-12 10:14:46 -05:00
|
|
|
|
BStringList params, BString line);
|
2021-08-09 14:06:04 -05:00
|
|
|
|
|
2021-08-10 10:00:26 -05:00
|
|
|
|
void _MakeReady(BString nick, BString ident);
|
|
|
|
|
|
2021-08-09 14:06:04 -05:00
|
|
|
|
BString _LineSender(BStringList words);
|
|
|
|
|
BString _LineCode(BStringList words);
|
2021-08-09 19:03:37 -05:00
|
|
|
|
BStringList _LineParameters(BStringList words, BString line);
|
2021-08-09 14:06:04 -05:00
|
|
|
|
|
|
|
|
|
void _SendMsg(BMessage* msg);
|
|
|
|
|
void _SendIrc(BString cmd);
|
|
|
|
|
|
2021-08-09 22:08:50 -05:00
|
|
|
|
// 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);
|
2021-08-16 00:42:39 -05:00
|
|
|
|
BString _NickIdent(BString nick);
|
2021-08-10 00:03:28 -05:00
|
|
|
|
|
2021-08-10 12:53:20 -05:00
|
|
|
|
bool _IsChannelName(BString name);
|
|
|
|
|
|
2021-08-12 20:16:22 -05:00
|
|
|
|
void _AddFormatted(BMessage* msg, const char* name,
|
|
|
|
|
BString text);
|
|
|
|
|
void _ToggleAndAdd(BMessage* msg, uint16 face, int32* start,
|
|
|
|
|
int32 current);
|
|
|
|
|
|
2021-08-16 00:42:39 -05:00
|
|
|
|
void _UpdateContact(BString nick, BString ident, bool online);
|
|
|
|
|
void _AddContact(BString nick);
|
|
|
|
|
void _RemoveContact(BString user_id);
|
|
|
|
|
void _RenameContact(BString user_id, BString newNick);
|
|
|
|
|
void _LoadContacts();
|
|
|
|
|
void _SaveContacts();
|
|
|
|
|
|
2021-08-16 16:11:37 -05:00
|
|
|
|
int32 _RolePerms(UserRole role);
|
|
|
|
|
const char* _RoleTitle(UserRole role);
|
|
|
|
|
|
2021-08-16 00:42:39 -05:00
|
|
|
|
const char* _CachePath();
|
|
|
|
|
const char* _ContactsCache();
|
|
|
|
|
|
2021-08-09 22:08:50 -05:00
|
|
|
|
// Read a data stream until newline found; if data found past
|
|
|
|
|
// newline, append to given buffer for later use
|
2021-08-09 14:06:04 -05:00
|
|
|
|
BString _ReadUntilNewline(BDataIO* data, BString* extraBuffer);
|
2021-08-09 22:08:50 -05:00
|
|
|
|
// Trim given string until newline hit, return trimmed part
|
2021-08-09 14:06:04 -05:00
|
|
|
|
BString _TrimStringToNewline(BString* str);
|
|
|
|
|
|
2021-08-09 22:08:50 -05:00
|
|
|
|
// GUI templates
|
2021-08-09 14:06:04 -05:00
|
|
|
|
BMessage _AccountTemplate();
|
|
|
|
|
BMessage _RoomTemplate();
|
2021-08-16 00:42:39 -05:00
|
|
|
|
BMessage _RosterTemplate();
|
2021-08-09 14:06:04 -05:00
|
|
|
|
|
|
|
|
|
BSocket* fSocket;
|
|
|
|
|
BString fRemainingBuf;
|
|
|
|
|
thread_id fRecvThread;
|
|
|
|
|
|
2021-08-13 14:32:46 -05:00
|
|
|
|
// Settings
|
2021-08-09 14:06:04 -05:00
|
|
|
|
BString fNick;
|
2021-08-13 14:32:46 -05:00
|
|
|
|
BString fUser;
|
2021-08-09 19:03:37 -05:00
|
|
|
|
BString fIdent;
|
2021-08-09 14:06:04 -05:00
|
|
|
|
BString fPartText;
|
2021-08-13 14:32:46 -05:00
|
|
|
|
BString fRealName;
|
|
|
|
|
BString fPassword;
|
|
|
|
|
BString fServer;
|
|
|
|
|
int32 fPort;
|
|
|
|
|
bool fSsl;
|
2021-06-20 22:17:24 -05:00
|
|
|
|
|
2021-08-09 22:08:50 -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;
|
2021-08-15 21:54:24 -05:00
|
|
|
|
bool fWhoIsRequested;
|
2021-08-15 20:44:34 -05:00
|
|
|
|
BString fWhoIm;
|
|
|
|
|
|
2021-08-10 12:53:20 -05:00
|
|
|
|
bool fWriteLocked;
|
2021-08-09 22:08:50 -05:00
|
|
|
|
|
2021-08-10 00:03:28 -05:00
|
|
|
|
StringMap fIdentNicks; // User ident → nick
|
|
|
|
|
|
2021-08-11 18:51:41 -05:00
|
|
|
|
BStringList fChannels;
|
|
|
|
|
|
2021-08-16 00:42:39 -05:00
|
|
|
|
BStringList fContacts;
|
|
|
|
|
BStringList fOfflineContacts;
|
|
|
|
|
|
2021-06-20 22:17:24 -05:00
|
|
|
|
BPath fAddOnPath;
|
2021-08-09 14:06:04 -05:00
|
|
|
|
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
|