parent
7d72b5152c
commit
dd77f246f8
|
@ -94,7 +94,7 @@ Conversation::ImMessage(BMessage* msg)
|
|||
|
||||
BString name = CommandName(body);
|
||||
BString args = CommandArgs(body);
|
||||
ChatCommand* cmd = _GetServer()->CommandById(name);
|
||||
ChatCommand* cmd = _GetServer()->CommandById(name, fLooper->GetInstance());
|
||||
|
||||
if (cmd == NULL) {
|
||||
_WarnUser(BString("That isn't a valid command. Try /help for a list."));
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*
|
||||
* Copyright 2021, Jaidyn Levesque. All rights reserved.
|
||||
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
||||
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
||||
* Copyright 2021, Jaidyn Levesque. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Andrea Anzani, andrea.anzani@gmail.com
|
||||
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
||||
* Jaidyn Levesque, jadedctrl@teknik.io
|
||||
*/
|
||||
|
||||
#include "ProtocolLooper.h"
|
||||
|
@ -142,6 +143,20 @@ ProtocolLooper::AddUser(User* user)
|
|||
}
|
||||
|
||||
|
||||
CommandMap
|
||||
ProtocolLooper::Commands() const
|
||||
{
|
||||
return fCommands;
|
||||
}
|
||||
|
||||
|
||||
ChatCommand*
|
||||
ProtocolLooper::CommandById(BString id)
|
||||
{
|
||||
return fCommands.ValueFor(id);
|
||||
}
|
||||
|
||||
|
||||
BString
|
||||
ProtocolLooper::GetOwnId()
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Copyright 2021, Jaidyn Levesque. All rights reserved.
|
||||
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
||||
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
||||
* Copyright 2021, Jaidyn Levesque. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _PROTOCOL_LOOPER_H
|
||||
|
@ -13,6 +13,7 @@
|
|||
#include <libsupport/KeyMap.h>
|
||||
|
||||
#include "CayaProtocol.h"
|
||||
#include "ChatCommand.h"
|
||||
|
||||
class Contact;
|
||||
class Conversation;
|
||||
|
@ -47,6 +48,9 @@ public:
|
|||
User* UserById(BString id);
|
||||
void AddUser(User* user);
|
||||
|
||||
CommandMap Commands() const;
|
||||
ChatCommand* CommandById(BString id);
|
||||
|
||||
BString GetOwnId();
|
||||
void SetOwnId(BString user_id);
|
||||
|
||||
|
@ -64,6 +68,7 @@ private:
|
|||
ChatMap fChatMap;
|
||||
RosterMap fRosterMap;
|
||||
UserMap fUserMap;
|
||||
CommandMap fCommands;
|
||||
|
||||
ConversationAccountItem*
|
||||
fListItem;
|
||||
|
|
|
@ -117,13 +117,14 @@ Server::Filter(BMessage* message, BHandler **target)
|
|||
{
|
||||
BString body;
|
||||
BString cmd_name = message->FindString("misc_str");
|
||||
int64 instance = message->FindInt64("instance");
|
||||
Conversation* chat = _EnsureConversation(message);
|
||||
|
||||
if (chat == NULL)
|
||||
break;
|
||||
|
||||
if (cmd_name.IsEmpty() == false) {
|
||||
ChatCommand* cmd = CommandById(cmd_name);
|
||||
ChatCommand* cmd = CommandById(cmd_name, instance);
|
||||
if (cmd == NULL)
|
||||
body = "-- That command doesn't exist. Try '/help' for a "
|
||||
"list.\n";
|
||||
|
@ -682,7 +683,6 @@ UserMap
|
|||
Server::Users() const
|
||||
{
|
||||
UserMap users;
|
||||
|
||||
for (int i = 0; i < fAccounts.CountItems(); i++) {
|
||||
ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i));
|
||||
if (fruitLoop == NULL) continue;
|
||||
|
@ -757,14 +757,29 @@ Server::AddConversation(Conversation* chat, int64 instance)
|
|||
CommandMap
|
||||
Server::Commands()
|
||||
{
|
||||
CommandMap commands = fCommands;
|
||||
for (int i = 0; i < fAccounts.CountItems(); i++) {
|
||||
ProtocolLooper* fruitLoop = fLoopers.ValueFor(fAccounts.ValueAt(i));
|
||||
if (fruitLoop == NULL) continue;
|
||||
|
||||
CommandMap cmds = fruitLoop->Commands();
|
||||
for (int i = 0; i < cmds.CountItems(); i++)
|
||||
commands.AddItem(cmds.KeyAt(i), cmds.ValueAt(i));
|
||||
}
|
||||
return fCommands;
|
||||
}
|
||||
|
||||
|
||||
ChatCommand*
|
||||
Server::CommandById(BString id)
|
||||
Server::CommandById(BString id, int64 instance)
|
||||
{
|
||||
return fCommands.ValueFor(id);
|
||||
ProtocolLooper* looper = fLoopers.ValueFor(instance);
|
||||
ChatCommand* result = NULL;
|
||||
if (looper != NULL)
|
||||
result = looper->CommandById(id);
|
||||
if (result == NULL)
|
||||
result = fCommands.ValueFor(id);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
void AddConversation(Conversation* chat, int64 instance);
|
||||
|
||||
CommandMap Commands();
|
||||
ChatCommand* CommandById(BString id);
|
||||
ChatCommand* CommandById(BString id, int64 instance);
|
||||
|
||||
private:
|
||||
ProtocolLooper* _LooperFromMessage(BMessage* message);
|
||||
|
|
Ŝarĝante…
Reference in New Issue