Repository navigation
Expand file tree
/
Copy pathObjComm.cpp
More file actions
203 lines (171 loc) · 5.09 KB
/
Copy pathObjComm.cpp
File metadata and controls
203 lines (171 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "stdafx.h"
#include "Vct.h"
#include "VctCtl.h"
#include "objcomm.h"
/************************************************************/
// CObjectBase base class implementation
/************************************************************/
CObjectBase::CObjectBase(){
m_pCtrl = NULL;
m_pVpComm = NULL;
}
CObjectBase::~CObjectBase(){
}
void CObjectBase::Advise(CVctCtrl* pCtrl){
m_pCtrl = pCtrl;
ASSERT(m_pCtrl);
}
void CObjectBase::Unadvise(){
m_pCtrl = NULL;
}
void CObjectBase::Advise(IVpComm* pVpComm){
if(!m_pVpComm){
m_pVpComm = pVpComm;
ASSERT(m_pVpComm);
}
}
void CObjectBase::VpUnadvise(){
m_pVpComm = NULL;
}
// Helper function for work with OLESTR
BSTR CObjectBase::DataToBSTR(void* pMsg, long len){
int iLen = (int)len;
return SysAllocStringLen(String16((char*)pMsg, iLen), iLen);
}
BOOL CObjectBase::DataToBSTR(BSTR* Data, const char* pMsg, long len){
int iLen = (int)len;
BOOL fl = SysReAllocStringLen(Data, String16(pMsg, iLen), iLen);
return fl;
}
void* CObjectBase::DataFromBSTR(BSTR bstrData, long& len){
len = SysStringLen(bstrData);
int iLen = (int)len;
String8 str8(bstrData, iLen);
char* pData = new char[iLen];
memcpy(pData, (char*)str8, iLen);
return (void*)pData;
}
BOOL CObjectBase::IsReady(){
return (m_pCtrl || m_pVpComm) ? TRUE : FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Commands & Requests from objects to VP
/////////////////////////////////////////////////////////////////////////////
short CObjectBase::send(long Id, short SendType, LPCTSTR Message, void* Data, long len){
if(!IsReady()) return -1;
BSTR bstrData = DataToBSTR(Data, len);
if(m_pCtrl)
m_pCtrl->e_Send(Id, SendType, Message, &bstrData);
else if(m_pVpComm)
m_pVpComm->Send(Id, SendType, Message, &bstrData);
::SysFreeString(bstrData);
return 0;
}
short CObjectBase::leaveGroup(){
if(!IsReady()) return -1;
if(m_pCtrl)
m_pCtrl->e_LeaveGroup();
else if(m_pVpComm)
m_pVpComm->LeaveGroup();
return 0;
}
short CObjectBase::enumMembers(long Id, short MaxLevel /*= 1*/){
if(!IsReady()) return -1;
if(m_pCtrl)
m_pCtrl->e_EnumMembers(Id, MaxLevel);
else if(m_pVpComm)
m_pVpComm->EnumMembers(Id, MaxLevel);
return 0;
}
short CObjectBase::sendToService(long ServiceId, long SrvSendType,
LPCTSTR Message, void* Data, long len, long ReqId){
if(!IsReady()) return -1;
BSTR bstrData = DataToBSTR(Data, len);
if(m_pCtrl)
m_pCtrl->e_SendToService(ServiceId, SrvSendType, Message, &bstrData, ReqId);
else if(m_pVpComm)
m_pVpComm->SendToService(ServiceId, SrvSendType, Message, &bstrData, ReqId);
::SysFreeString(bstrData);
return 0;
}
short CObjectBase::queryService(long& Id, short& Type){
if(!IsReady()) return -1;
if(m_pCtrl)
m_pCtrl->e_QueryService(&Id, &Type);
else if(m_pVpComm)
m_pVpComm->QueryService(&Id, &Type);
return 0;
}
short CObjectBase::getPresenceInfo(long Id, CString& Name, CString& Fullname,
CString& Location, CString& Email){
if(!IsReady()) return -1;
// Observation: Could this be any more fucking inefficient?
char* empty = "";
BSTR bstrName = DataToBSTR(empty, 1);
BSTR bstrFullname = DataToBSTR(empty, 1);
BSTR bstrLocation = DataToBSTR(empty, 1);
BSTR bstrEmail = DataToBSTR(empty, 1);
if(m_pCtrl)
m_pCtrl->e_GetPresenceInfo(Id, &bstrName, &bstrFullname, &bstrLocation, &bstrEmail);
else if(m_pVpComm)
m_pVpComm->GetPresenceInfo(Id, &bstrName, &bstrFullname, &bstrLocation, &bstrEmail);
long len;
char *p;
p = (char*)DataFromBSTR(bstrName, len);
Name = p;
delete p;
p = (char*)DataFromBSTR(bstrFullname, len);
Fullname = p;
delete p;
p = (char*)DataFromBSTR(bstrLocation, len);
Location = p;
delete p;
p = (char*)DataFromBSTR(bstrEmail, len);
Email = p;
delete p;
::SysFreeString(bstrName);
::SysFreeString(bstrFullname);
::SysFreeString(bstrLocation);
::SysFreeString(bstrEmail);
return 0;
}
CString CObjectBase::getPlaceName(){
if(!IsReady()) return "";
CString szURL;
if(m_pVpComm)
szURL = m_pVpComm->GetPlaceName();
return szURL;
}
/////////////////////////////////////////////////////////////////////////////
// VP service methods
/////////////////////////////////////////////////////////////////////////////
HWND CObjectBase::getParentWnd(){
if(!IsReady()) return NULL;
long hWnd = 0;
if(m_pCtrl)
m_pCtrl->e_GetParentWnd(&hWnd);
else if(m_pVpComm)
m_pVpComm->GetParentWnd(&hWnd);
return hWnd ? (HWND)hWnd : NULL;
}
void CObjectBase::setGameWnd(HWND hWnd){
if(!IsReady()) return;
if(m_pCtrl)
m_pCtrl->e_SetGameWnd((long)((int)hWnd));
else if(m_pVpComm)
m_pVpComm->SetGameWnd((long)((int)hWnd));
}
void CObjectBase::dupAvatar(HWND ParentWnd, short nSeat){
if(!IsReady()) return;
if(m_pCtrl)
m_pCtrl->e_DupAvatar((long)((int)ParentWnd), nSeat);
else if(m_pVpComm)
m_pVpComm->DupAvatar((long)((int)ParentWnd), nSeat);
}
void CObjectBase::setAvatarPos(short Seat, short Left, short Top, short Width, short Height){
if(!IsReady()) return;
if(m_pCtrl)
m_pCtrl->e_SetAvatarPos(Seat, Left, Top, Width, Height);
else if(m_pVpComm)
m_pVpComm->SetAvatarPos(Seat, Left, Top, Width, Height);
}