dce82c2ba2
Instead of passing around pointers to the Server, Server::Get() returns the server's pointer (simplifying some things a good bit). As a result, headers have been cleaned up, and some redundant KeyMaps have been placed in Maps.h.
121 lines
2.2 KiB
C++
121 lines
2.2 KiB
C++
/*
|
|
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*
|
|
* Authors:
|
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
|
*/
|
|
|
|
#include "StatusManager.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "ChatProtocolMessages.h"
|
|
#include "NotifyMessage.h"
|
|
#include "Server.h"
|
|
|
|
|
|
static StatusManager* fInstance = NULL;
|
|
|
|
|
|
StatusManager::StatusManager()
|
|
:
|
|
fStatus(STATUS_OFFLINE),
|
|
fReplicantMessenger(NULL)
|
|
{
|
|
}
|
|
|
|
|
|
StatusManager::~StatusManager()
|
|
{
|
|
delete fReplicantMessenger;
|
|
}
|
|
|
|
|
|
StatusManager*
|
|
StatusManager::Get()
|
|
{
|
|
if (fInstance == NULL)
|
|
fInstance = new StatusManager();
|
|
return fInstance;
|
|
}
|
|
|
|
|
|
void
|
|
StatusManager::SetNickname(BString nick, int64 instance)
|
|
{
|
|
// Create message
|
|
BMessage* msg = new BMessage(IM_MESSAGE);
|
|
msg->AddInt32("im_what", IM_SET_OWN_NICKNAME);
|
|
msg->AddString("user_name", nick);
|
|
|
|
// Send message
|
|
if (instance > -1) {
|
|
msg->AddInt64("instance", instance);
|
|
Server::Get()->SendProtocolMessage(msg);
|
|
}
|
|
else
|
|
Server::Get()->SendAllProtocolMessage(msg);
|
|
}
|
|
|
|
|
|
void
|
|
StatusManager::SetReplicantMessenger(BMessenger* messenger)
|
|
{
|
|
fReplicantMessenger = messenger;
|
|
}
|
|
|
|
|
|
UserStatus
|
|
StatusManager::Status() const
|
|
{
|
|
return fStatus;
|
|
}
|
|
|
|
|
|
void
|
|
StatusManager::SetStatus(UserStatus status, const char* str, int64 instance)
|
|
{
|
|
if (fStatus == status && instance == -1)
|
|
return;
|
|
|
|
// Create status change message
|
|
BMessage* msg = new BMessage(IM_MESSAGE);
|
|
msg->AddInt32("im_what", IM_SET_OWN_STATUS);
|
|
msg->AddInt32("status", (int32)status);
|
|
if (str != NULL)
|
|
msg->AddString("message", str);
|
|
|
|
// Send message
|
|
if (instance > -1) {
|
|
msg->AddInt64("instance", instance);
|
|
Server::Get()->SendProtocolMessage(msg);
|
|
}
|
|
else
|
|
Server::Get()->SendAllProtocolMessage(msg);
|
|
|
|
// Notify status change
|
|
fStatus = status;
|
|
NotifyInteger(INT_ACCOUNT_STATUS, (int32)fStatus);
|
|
ReplicantStatusNotify((UserStatus)status);
|
|
}
|
|
|
|
|
|
void
|
|
StatusManager::SetStatus(UserStatus status, int64 instance)
|
|
{
|
|
SetStatus(status, NULL, instance);
|
|
}
|
|
|
|
|
|
void
|
|
StatusManager::ReplicantStatusNotify(UserStatus status, bool wait)
|
|
{
|
|
if(fReplicantMessenger != NULL && fReplicantMessenger->IsValid()) {
|
|
printf("notification sent\n");
|
|
BMessage mess(IM_OWN_STATUS_SET);
|
|
mess.AddInt32("status", status);
|
|
fReplicantMessenger->SendMessage(&mess);
|
|
}
|
|
}
|