summaryrefslogtreecommitdiff
path: root/plugins/NewAwaySysMod/src/Services.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/NewAwaySysMod/src/Services.cpp')
-rw-r--r--plugins/NewAwaySysMod/src/Services.cpp82
1 files changed, 23 insertions, 59 deletions
diff --git a/plugins/NewAwaySysMod/src/Services.cpp b/plugins/NewAwaySysMod/src/Services.cpp
index 392d318222..44aa93e633 100644
--- a/plugins/NewAwaySysMod/src/Services.cpp
+++ b/plugins/NewAwaySysMod/src/Services.cpp
@@ -22,39 +22,24 @@
#include "Properties.h"
#include "m_NewAwaySys.h"
-
-typedef struct {
+struct NAS_PROTOINFOv1
+{
int cbSize;
char *szProto;
- union
- {
+ union {
char *szMsg;
WCHAR *wszMsg;
TCHAR *tszMsg;
};
WORD status;
-} NAS_PROTOINFOv1;
-
+};
__inline void PSSetStatus(char *szProto, WORD Status, int bNoClistSetStatusMode = false) // just a helper function that sets the status and handles szProto==NULL correctly
{
g_ProtoStates[szProto].Status = Status;
if (szProto)
- {
CallProtoService(szProto, PS_SETSTATUS, Status, 0);
- } else if (!bNoClistSetStatusMode) // global status
- {
-/* int ProtoCount;
- PROTOCOLDESCRIPTOR **proto;
- CallService(MS_PROTO_ENUMACCOUNTS, (WPARAM)&ProtoCount, (LPARAM)&proto);
- int i;
- for (i = 0; i < ProtoCount; i++)
- {
- if (proto[i]->type == PROTOTYPE_PROTOCOL)
- {
- CallProtoService(proto[i]->szName, PS_SETSTATUS, Status, 0);
- }
- }*/
+ else if (!bNoClistSetStatusMode) { // global status
g_fNoProcessing = true;
CallService(MS_CLIST_SETSTATUSMODE, Status, 0);
_ASSERT(!g_fNoProcessing && g_ProtoStates[(char*)NULL].Status == Status);
@@ -62,19 +47,17 @@ __inline void PSSetStatus(char *szProto, WORD Status, int bNoClistSetStatusMode
}
}
-
-INT_PTR GetStatusMsg(WPARAM wParam, LPARAM lParam) // called by GamerStatus and built-in miranda autoaway module
+// called by GamerStatus and built-in miranda autoaway module
// wParam = (int)status, lParam = 0
// MS_AWAYMSG_GETSTATUSMSG "SRAway/GetStatusMessage"
+INT_PTR GetStatusMsg(WPARAM wParam, LPARAM lParam)
{
LogMessage("MS_AWAYMSG_GETSTATUSMSG called. status=%d", wParam);
CString Msg(_T2A(GetDynamicStatMsg(INVALID_CONTACT_ID, NULL, 0, wParam)));
char *szMsg;
- if (Msg == NULL)
- { // it's ok to return NULL, so we'll do it
+ if (Msg == NULL) // it's ok to return NULL, so we'll do it
szMsg = NULL;
- } else
- {
+ else {
szMsg = (char*)mir_alloc(Msg.GetLen() + 1);
lstrcpyA(szMsg, Msg);
}
@@ -82,17 +65,14 @@ INT_PTR GetStatusMsg(WPARAM wParam, LPARAM lParam) // called by GamerStatus and
return (int)szMsg;
}
-
-INT_PTR SetStatusMode(WPARAM wParam, LPARAM lParam) // called by GamerStatus and StatCtrl
-{
// wParam = int iMode
// lParam = char* szMsg, may be null - then we need to use the default message
-/* if (CallService(MS_CLIST_GETSTATUSMODE, 0, 0) != wParam) // not same status
- {*/ // try this way; global status may be not the same as current status of some separate protocol
+INT_PTR SetStatusMode(WPARAM wParam, LPARAM lParam) // called by GamerStatus and StatCtrl
+{
LogMessage("MS_AWAYSYS_SETSTATUSMODE called. status=%d, szMsg:\n%s", wParam, lParam ? (char*)lParam : "NULL");
g_fNoProcessing = true;
CallService(MS_CLIST_SETSTATUSMODE, wParam, 0);
-// }
+
_ASSERT(!g_fNoProcessing && g_ProtoStates[(char*)NULL].Status == wParam);
g_fNoProcessing = false;
CProtoSettings(NULL, wParam).SetMsgFormat(SMF_TEMPORARY, lParam ? (TCHAR*)_A2T((char*)lParam) : CProtoSettings(NULL, wParam).GetMsgFormat(GMF_LASTORDEFAULT));
@@ -100,26 +80,22 @@ INT_PTR SetStatusMode(WPARAM wParam, LPARAM lParam) // called by GamerStatus and
return 0;
}
-
-int GetState(WPARAM wParam, LPARAM lParam, int Widechar)
// wParam = (WPARAM)(NAS_PROTOINFO*)pi - pointer to an array of NAS_PROTOINFO items to be filled.
// lParam = (LPARAM)(int)protoCount - number of items in pi.
// returns 0 on success
+int GetState(WPARAM wParam, LPARAM lParam, int Widechar)
{
NAS_PROTOINFO *pi = (NAS_PROTOINFO*)wParam;
LogMessage("MS_NAS_GETSTATE called with %d items and Widechar=%d:", lParam, Widechar);
- for (int i = 0; i < lParam; i++)
- {
+ for (int i = 0; i < lParam; i++) {
if (pi->cbSize < sizeof(NAS_PROTOINFO) && pi->cbSize != sizeof(NAS_PROTOINFOv1))
return 1;
int Flags = (pi->cbSize > sizeof(NAS_PROTOINFOv1)) ? pi->Flags : 0;
LogMessage("%d (received): cbSize=%d, status=%d, szProto=%s, Flags=0x%x", i + 1, pi->cbSize, pi->status, pi->szProto ? pi->szProto : "NULL", Flags);
- if ((pi->status >= ID_STATUS_ONLINE && pi->status <= ID_STATUS_OUTTOLUNCH) || !pi->status)
- {
+ if ((pi->status >= ID_STATUS_ONLINE && pi->status <= ID_STATUS_OUTTOLUNCH) || !pi->status) {
TCString Msg(pi->status ? CProtoSettings(pi->szProto, pi->status).GetMsgFormat(GMF_LASTORDEFAULT) : CProtoSettings(pi->szProto).GetMsgFormat(((Flags & PIF_NOTTEMPORARY) ? 0 : GMF_TEMPORARY) | GMF_PERSONAL));
- if (Msg != NULL)
- {
+ if (Msg != NULL) {
pi->szMsg = (char*)mir_alloc(Msg.GetLen() + 1);
_ASSERT(pi->szMsg);
if (Widechar)
@@ -140,28 +116,24 @@ int GetState(WPARAM wParam, LPARAM lParam, int Widechar)
return 0;
}
-
INT_PTR GetStateA(WPARAM wParam, LPARAM lParam)
{
return GetState(wParam, lParam, false);
}
-
INT_PTR GetStateW(WPARAM wParam, LPARAM lParam)
{
return GetState(wParam, lParam, true);
}
-
-int SetState(WPARAM wParam, LPARAM lParam, int Widechar)
// wParam = (WPARAM)(NAS_PROTOINFO*)pi - pointer to an array of NAS_PROTOINFO items.
// lParam = (LPARAM)(int)protoCount - number of items in pi.
// returns 0 on success
+int SetState(WPARAM wParam, LPARAM lParam, int Widechar)
{
NAS_PROTOINFO *pi = (NAS_PROTOINFO*)wParam;
LogMessage("MS_NAS_SETSTATE called with %d items and Widechar=%d:", lParam, Widechar);
- for (int i = 0; i < lParam; i++)
- {
+ for (int i = 0; i < lParam; i++) {
_ASSERT(pi->szMsg != (char*)(-1));
if (pi->cbSize < sizeof(NAS_PROTOINFO) && pi->cbSize != sizeof(NAS_PROTOINFOv1))
return 1;
@@ -184,37 +156,31 @@ int SetState(WPARAM wParam, LPARAM lParam, int Widechar)
return 0;
}
-
INT_PTR SetStateA(WPARAM wParam, LPARAM lParam)
{
return SetState(wParam, lParam, false);
}
-
INT_PTR SetStateW(WPARAM wParam, LPARAM lParam)
{
return SetState(wParam, lParam, true);
}
-
-INT_PTR InvokeStatusWindow(WPARAM wParam, LPARAM lParam)
// wParam = (WPARAM)(NAS_ISWINFO*)iswi - pointer to a NAS_ISWINFO structure.
// lParam = 0
// returns HWND of the window on success, or NULL on failure.
+INT_PTR InvokeStatusWindow(WPARAM wParam, LPARAM lParam)
{
NAS_ISWINFO *iswi = (NAS_ISWINFO*)wParam;
if (iswi->cbSize != sizeof(NAS_ISWINFOv1) && iswi->cbSize < sizeof(NAS_ISWINFO))
- {
return NULL;
- }
+
LogMessage("MS_NAS_INVOKESTATUSWINDOW called. cbSize=%d, status=%d, szProto=%s, hContact=0x%08x, Flags=0x%x, szMsg:\n%s", iswi->cbSize, iswi->status, iswi->szProto ? iswi->szProto : "NULL", iswi->hContact, (iswi->cbSize < sizeof(NAS_ISWINFO)) ? 0 : iswi->Flags, iswi->szMsg ? ((iswi->Flags & ISWF_UNICODE) ? _T2A(iswi->wszMsg) : iswi->szMsg) : "NULL");
if (iswi->status)
- {
PSSetStatus(iswi->szProto, iswi->status);
- }
- if (g_SetAwayMsgPage.GetWnd()) // already setting something
- {
- SetForegroundWindow(g_SetAwayMsgPage.GetWnd());
+
+ if (g_SetAwayMsgPage.GetWnd()) { // already setting something
+ SetForegroundWindow(g_SetAwayMsgPage.GetWnd());
return (int)g_SetAwayMsgPage.GetWnd();
}
SetAwayMsgData *dat = new SetAwayMsgData;
@@ -224,8 +190,6 @@ INT_PTR InvokeStatusWindow(WPARAM wParam, LPARAM lParam)
dat->Message = (iswi->Flags & ISWF_UNICODE) ? iswi->wszMsg : _A2T(iswi->szMsg);
dat->IsModeless = true;
if (iswi->cbSize > sizeof(NAS_ISWINFOv1))
- {
dat->ISW_Flags = iswi->Flags;
- }
return (int)CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_SETAWAYMSG), NULL, SetAwayMsgDlgProc, (LPARAM)dat);
}