summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-06-30 15:07:52 +0000
committersje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2007-06-30 15:07:52 +0000
commita68efd9f17a4255a22d7e63741d723f986b23d0e (patch)
tree619b53eb47952b0b9a1eaa7d3324cbba23e28560
parent16827df7bc4a82d74f89dc81631bd2a7d05f3121 (diff)
download buddies
set status on server added away and invisible status git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@221 4f64403b-2f21-0410-a795-97e2b3489a10
-rw-r--r--MySpace/MySpace.cpp15
-rw-r--r--MySpace/MySpace.rc39
-rw-r--r--MySpace/MySpace.vcproj17
-rw-r--r--MySpace/common.h2
-rw-r--r--MySpace/options.cpp19
-rw-r--r--MySpace/options.h12
-rw-r--r--MySpace/proto.cpp104
-rw-r--r--MySpace/proto.h6
-rw-r--r--MySpace/resource.h9
-rw-r--r--MySpace/server_con.cpp374
-rw-r--r--MySpace/server_con.h8
11 files changed, 413 insertions, 192 deletions
diff --git a/MySpace/MySpace.cpp b/MySpace/MySpace.cpp
index cb1da5d..aa229b5 100644
--- a/MySpace/MySpace.cpp
+++ b/MySpace/MySpace.cpp
@@ -60,6 +60,19 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) {
return 0;
}
+void SetAllOffline() {
+ char *proto;
+ HANDLE hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDFIRST, 0, 0 );
+ while ( hContact != NULL )
+ {
+ proto = ( char* )CallService( MS_PROTO_GETCONTACTBASEPROTO, ( WPARAM )hContact,0 );
+ if ( proto && !strcmp( MODULE, proto)) {
+ DBWriteContactSettingWord(hContact, MODULE, "Status", ID_STATUS_OFFLINE);
+ }
+ hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDNEXT,( WPARAM )hContact, 0 );
+ }
+}
+
HANDLE hModulesLoaded;
extern "C" __declspec (dllexport) int Load(PLUGINLINK *link) {
DuplicateHandle( GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &mainThread, THREAD_SET_CONTEXT, FALSE, 0 );
@@ -76,6 +89,8 @@ extern "C" __declspec (dllexport) int Load(PLUGINLINK *link) {
RegisterProto();
CreateProtoServices();
+ SetAllOffline();
+
// hook modules loaded
hModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded);
return 0;
diff --git a/MySpace/MySpace.rc b/MySpace/MySpace.rc
index 8d49b6f..0652d1a 100644
--- a/MySpace/MySpace.rc
+++ b/MySpace/MySpace.rc
@@ -104,12 +104,51 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_AUS
/////////////////////////////////////////////////////////////////////////////
//
+// Dialog
+//
+
+IDD_NICK DIALOGEX 0, 0, 339, 175
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "MySpace - Choose Nick Name"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ DEFPUSHBUTTON "OK",IDOK,115,154,50,14,WS_DISABLED
+ PUSHBUTTON "Cancel",IDCANCEL,173,154,50,14
+ CTEXT "Before you can use the MySpace IM network, you must choose a unique nick name.",IDC_STATIC,92,23,154,35
+ EDITTEXT IDC_ED_NICK,124,57,113,14,ES_AUTOHSCROLL
+ RTEXT "NickName:",IDC_STATIC,67,60,51,8
+ PUSHBUTTON "Check if Available",IDC_BTN_CHECK,120,81,103,14,WS_DISABLED
+ CTEXT "Fill in the box above and click the button to see whether the nick name you have chosen is allowed.",IDC_ST_MSG,95,106,149,42
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON_PROTO ICON "icon1.ico"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+ IDD_NICK, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 332
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 168
+ END
+END
+#endif // APSTUDIO_INVOKED
+
#endif // English (Australia) resources
/////////////////////////////////////////////////////////////////////////////
diff --git a/MySpace/MySpace.vcproj b/MySpace/MySpace.vcproj
index 9e6d124..0a5889f 100644
--- a/MySpace/MySpace.vcproj
+++ b/MySpace/MySpace.vcproj
@@ -267,6 +267,7 @@
/>
<Tool
Name="VCLinkerTool"
+ GenerateDebugInformation="false"
SubSystem="2"
/>
<Tool
@@ -360,6 +361,10 @@
>
</File>
<File
+ RelativePath=".\nick_dialog.cpp"
+ >
+ </File>
+ <File
RelativePath=".\options.cpp"
>
</File>
@@ -367,6 +372,10 @@
RelativePath=".\proto.cpp"
>
</File>
+ <File
+ RelativePath=".\server_con.cpp"
+ >
+ </File>
</Filter>
<Filter
Name="Header Files"
@@ -398,19 +407,19 @@
>
</File>
<File
- RelativePath=".\options.h"
+ RelativePath=".\nick_dialog.h"
>
</File>
<File
- RelativePath=".\proto.h"
+ RelativePath=".\options.h"
>
</File>
<File
- RelativePath=".\resource.h"
+ RelativePath=".\proto.h"
>
</File>
<File
- RelativePath=".\server_con.cpp"
+ RelativePath=".\resource.h"
>
</File>
<File
diff --git a/MySpace/common.h b/MySpace/common.h
index 1a7ae63..c74cb99 100644
--- a/MySpace/common.h
+++ b/MySpace/common.h
@@ -67,4 +67,6 @@ extern PLUGINLINK *pluginLink;
extern HANDLE mainThread;
extern int code_page;
+void SetAllOffline();
+
#endif
diff --git a/MySpace/options.cpp b/MySpace/options.cpp
index 0da55b7..cf592d8 100644
--- a/MySpace/options.cpp
+++ b/MySpace/options.cpp
@@ -14,15 +14,32 @@ void LoadOptions() {
_tcsncpy(options.pw, dbv.ptszVal, 256);
DBFreeVariant(&dbv);
}
+
+ options.sound = (DBGetContactSettingByte(0, MODULE, "sound", 0) != 0);
+ options.privacy_mode = (PrivacyMode)DBGetContactSettingByte(0, MODULE, "privacy_mode", PM_ANYONE);
+ options.show_only_to_list = (DBGetContactSettingByte(0, MODULE, "show_only_to_list", 0) != 0);
+ options.offline_message_mode = (OfflineMessageMode)DBGetContactSettingByte(0, MODULE, "offline_message_mode", OMM_CLIST);;
+ options.show_avatar = (DBGetContactSettingByte(0, MODULE, "show_avatar", 0) != 0);
+ if(!DBGetContactSettingStringUtf(0, MODULE, "Nick", &dbv)) {
+ strncpy(options.im_name, dbv.pszVal, 256);
+ DBFreeVariant(&dbv);
+ }
}
void SaveOptions() {
DBWriteContactSettingTString(0, MODULE, "email", options.email);
DBWriteContactSettingTString(0, MODULE, "pw", options.pw);
+
+ DBWriteContactSettingByte(0, MODULE, "sound", options.sound ? 1 : 0);
+ DBWriteContactSettingByte(0, MODULE, "privacy_mode", (BYTE)options.privacy_mode);
+ DBWriteContactSettingByte(0, MODULE, "show_only_to_list", options.show_only_to_list ? 1 : 0);
+ DBWriteContactSettingByte(0, MODULE, "offline_message_mode", (BYTE)options.offline_message_mode);
+ DBWriteContactSettingByte(0, MODULE, "show_avatar", options.show_avatar ? 1 : 0);
+ DBWriteContactSettingStringUtf(0, MODULE, "Nick", options.im_name);
}
BOOL CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
- static HANDLE hItemAll;
+ //static HANDLE hItemAll;
switch ( msg ) {
case WM_INITDIALOG:
diff --git a/MySpace/options.h b/MySpace/options.h
index 2aea34c..da190c8 100644
--- a/MySpace/options.h
+++ b/MySpace/options.h
@@ -1,9 +1,21 @@
#ifndef _OPTIONS_INC
#define _OPTIONS_INC
+typedef enum {PM_ANYONE, PM_CLIST} PrivacyMode;
+typedef enum {OMM_EVERYONE, OMM_CLIST, OMM_NOONE} OfflineMessageMode;
+
+
typedef struct {
TCHAR email[256];
TCHAR pw[256];
+
+ // im options
+ bool sound;
+ PrivacyMode privacy_mode;
+ bool show_only_to_list;
+ OfflineMessageMode offline_message_mode;
+ bool show_avatar;
+ char im_name[256];
} Options;
extern Options options;
diff --git a/MySpace/proto.cpp b/MySpace/proto.cpp
index 60577b1..15bc91f 100644
--- a/MySpace/proto.cpp
+++ b/MySpace/proto.cpp
@@ -12,14 +12,16 @@ int GetCaps(WPARAM wParam,LPARAM lParam) {
ret = PF1_NUMERICUSERID | PF1_IM | PF1_BASICSEARCH | PF1_SEARCHBYEMAIL | PF1_SEARCHBYNAME | PF1_ADDSEARCHRES | PF1_SERVERCLIST;
break;
case PFLAGNUM_2:
- ret = PF2_ONLINE;// | PF2_SHORTAWAY | PF2_HEAVYDND;
+ ret = PF2_ONLINE | PF2_SHORTAWAY | PF2_INVISIBLE;
break;
case PFLAGNUM_3:
- //ret = PF2_ONLINE;// | PF2_SHORTAWAY | PF2_HEAVYDND;
break;
case PFLAGNUM_4:
//ret = PF4_SUPPORTTYPING;
break;
+ case PFLAGNUM_5:
+ //ret = PF2_INVISIBLE;
+ break;
case PFLAG_UNIQUEIDTEXT:
ret = (int) Translate("UserID");
break;
@@ -69,10 +71,7 @@ int GetInfo(WPARAM wParam,LPARAM lParam) {
int SetStatus(WPARAM wParam,LPARAM lParam) {
if(wParam == status) return 0;
- if(wParam != ID_STATUS_OFFLINE)
- InitServerConnection();
- else
- DeinitServerConnection();
+ SetServerStatus(wParam);
return 0;
}
@@ -192,96 +191,21 @@ int SearchByName(WPARAM wParam, LPARAM lParam) {
return req;
}
-HANDLE FindContact(int uid) {
- char *proto;
- DBVARIANT dbv;
- int cuid;
- HANDLE hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDFIRST, 0, 0 );
- while ( hContact != NULL )
- {
- proto = ( char* )CallService( MS_PROTO_GETCONTACTBASEPROTO, ( WPARAM )hContact,0 );
- if ( proto && !strcmp( MODULE, proto)) {
- cuid = DBGetContactSettingDword(hContact, MODULE, "UID", (DWORD)-1);
- if(cuid != (DWORD)-1) {
- return hContact;
- }
- }
- hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDNEXT,( WPARAM )hContact, 0 );
- }
-
- return 0;
-}
-
int AddToList(WPARAM wParam, LPARAM lParam) {
MYPROTOSEARCHRESULT *mpsr = (MYPROTOSEARCHRESULT *)lParam;
bool temp = (wParam & PALF_TEMPORARY) != 0;
HANDLE hContact = FindContact(mpsr->uid);
- bool new_contact = (hContact == 0);
if(!hContact) {
- hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0);
- } else if(!temp) {
- DBDeleteContactSetting(hContact, "CList", "NotOnList");
- DBDeleteContactSetting(hContact, "CList", "Hidden");
+ hContact = CreateContact(mpsr->uid, mpsr->psr.nick, mpsr->psr.email);
}
- if(hContact) {
- // add to miranda
- if(new_contact) {
- DBWriteContactSettingDword(hContact, MODULE, "UID", mpsr->uid);
-
- ClientNetMessage msg_add;
- msg_add.add_string("addbuddy", "");
- msg_add.add_int("sesskey", sesskey);
- msg_add.add_int("newprofileid", mpsr->uid);
- msg_add.add_string("reason", "");
-
- SendMessage(msg_add);
-
- ClientNetMessage msg_block;
- msg_block.add_string("blocklist", "");
- msg_block.add_int("sesskey", sesskey);
-
- char idlist[1024];
- mir_snprintf(idlist, 1024, "b-|%d|a+|%d", mpsr->uid, mpsr->uid);
- msg_block.add_string("idlist", idlist);
-
- SendMessage(msg_block);
-
- // update contact details?
- ClientNetMessage msg_persist;
- msg_persist.add_int("persist", 1);
- msg_persist.add_int("sesskey", sesskey);
-
- msg_persist.add_int("cmd", 514);
- msg_persist.add_int("dsn", 0);
- msg_persist.add_int("uid", DBGetContactSettingDword(0, MODULE, "UID", 0));
- msg_persist.add_int("lid", 9);
- msg_persist.add_int("rid", req_id++);
- char body[4096];
- mir_snprintf(body, 4096, "ContactID=%d\x1cGroupName=\x1cPosition=1000\x1cVisibility=1\x1cNickName=\x1cNameSelect=0", mpsr->uid);
- msg_persist.add_string("body", body);
- SendMessage(msg_persist);
- }
-
- if(mpsr->psr.nick && strlen(mpsr->psr.nick)) {
- DBWriteContactSettingStringUtf(hContact, MODULE, "Nick", mpsr->psr.nick);
- }
- if(mpsr->psr.email && strlen(mpsr->psr.email)) {
- DBWriteContactSettingStringUtf(hContact, MODULE, "email", mpsr->psr.email);
- }
-
- if(new_contact) {
- CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)MODULE);
- }
-
- if(temp) {
- DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1);
- DBWriteContactSettingByte(hContact, "CList", "Hidden", 1);
- } else {
- DBDeleteContactSetting(hContact, "CList", "NotOnList");
- DBDeleteContactSetting(hContact, "CList", "Hidden");
- }
+ if(temp) {
+ DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1);
+ DBWriteContactSettingByte(hContact, "CList", "Hidden", 1);
+ } else {
+ DBDeleteContactSetting(hContact, "CList", "NotOnList");
+ DBDeleteContactSetting(hContact, "CList", "Hidden");
}
return (int)hContact;
@@ -331,7 +255,7 @@ void RegisterProto() {
CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd);
}
-#define NUM_FILTER_SERVICES 12
+#define NUM_FILTER_SERVICES 13
HANDLE hServices[NUM_FILTER_SERVICES];
HANDLE hEventContactDeleted;
@@ -356,6 +280,8 @@ void CreateProtoServices() {
// remember to modify the NUM_FILTER_SERVICES #define above if you add more services!
hEventContactDeleted = HookEvent(ME_DB_CONTACT_DELETED, ContactDeleted);
+
+ //my_space_server_running = false;
}
void DeinitProto() {
diff --git a/MySpace/proto.h b/MySpace/proto.h
index 008c9f5..d45c485 100644
--- a/MySpace/proto.h
+++ b/MySpace/proto.h
@@ -1,12 +1,6 @@
#ifndef _PROTO_INC
#define _PROTO_INC
-typedef struct user {
- int uin;
- char *email;
- char *username;
-} UserType;
-
void RegisterProto();
void CreateProtoServices();
void DeinitProto();
diff --git a/MySpace/resource.h b/MySpace/resource.h
index a9d9bb1..50c44ff 100644
--- a/MySpace/resource.h
+++ b/MySpace/resource.h
@@ -6,16 +6,21 @@
#define IDI_MENU 110
#define IDI_ICON1 120
#define IDI_ICON_PROTO 120
+#define IDD_NICK 121
#define IDC_ED_EMAIL 1001
#define IDC_ED_PW 1002
+#define IDC_ED_NICK 1002
+#define IDC_BUTTON1 1003
+#define IDC_BTN_CHECK 1003
+#define IDC_ST_MSG 1004
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 121
+#define _APS_NEXT_RESOURCE_VALUE 122
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1002
+#define _APS_NEXT_CONTROL_VALUE 1005
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/MySpace/server_con.cpp b/MySpace/server_con.cpp
index 0aa577c..41aad7d 100644
--- a/MySpace/server_con.cpp
+++ b/MySpace/server_con.cpp
@@ -3,6 +3,7 @@
#include "net.h"
#include "arc4.h"
#include "options.h"
+#include "nick_dialog.h"
#define SERVER_READ_BUFFER_SIZE (1024 * 32)
@@ -22,10 +23,103 @@
#define NONCE_SIZE 0x20
int status = ID_STATUS_OFFLINE;
-bool server_running = false, server_stop = false;
+bool myspace_server_running = false, server_stop = false;
HANDLE server_connection = 0;
-int sesskey = 0, req_id = 1;
+int sesskey = 0, req_id = 1, my_uid = 0;
+int signon_status = ID_STATUS_ONLINE;
+
+int stat_mir_to_myspace(int mir_status) {
+ switch(mir_status) {
+ case ID_STATUS_INVISIBLE: return 0;
+ case ID_STATUS_AWAY: return 5;
+ case ID_STATUS_ONLINE: return 1;
+ }
+ return 0;
+}
+
+int stat_myspace_to_mir(int myspace_status) {
+ switch(myspace_status) {
+ case 0: return ID_STATUS_OFFLINE;
+ case 1: return ID_STATUS_ONLINE;
+ case 5: return ID_STATUS_AWAY;
+ }
+ return 0;
+}
+
+HANDLE FindContact(int uid) {
+ char *proto;
+ int cuid;
+ HANDLE hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDFIRST, 0, 0 );
+ while ( hContact != NULL )
+ {
+ proto = ( char* )CallService( MS_PROTO_GETCONTACTBASEPROTO, ( WPARAM )hContact,0 );
+ if ( proto && !strcmp( MODULE, proto)) {
+ cuid = DBGetContactSettingDword(hContact, MODULE, "UID", (DWORD)0);
+ if(cuid == uid) {
+ return hContact;
+ }
+ }
+ hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDNEXT,( WPARAM )hContact, 0 );
+ }
+
+ return 0;
+}
+
+HANDLE CreateContact(int uid, char *nick, char *email) {
+ HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0);
+
+ if(hContact) {
+ DBWriteContactSettingDword(hContact, MODULE, "UID", uid);
+ if(nick && strlen(nick)) {
+ DBWriteContactSettingStringUtf(hContact, MODULE, "Nick", nick);
+ }
+ if(email && strlen(email)) {
+ DBWriteContactSettingStringUtf(hContact, MODULE, "email", email);
+ }
+
+ ClientNetMessage msg_add;
+ msg_add.add_string("addbuddy", "");
+ msg_add.add_int("sesskey", sesskey);
+ msg_add.add_int("newprofileid", uid);
+ msg_add.add_string("reason", "");
+
+ SendMessage(msg_add);
+
+ /*
+ ClientNetMessage msg_block;
+ msg_block.add_string("blocklist", "");
+ msg_block.add_int("sesskey", sesskey);
+
+ char idlist[1024];
+ mir_snprintf(idlist, 1024, "b-|%d|a+|%d", mpsr->uid, mpsr->uid);
+ msg_block.add_string("idlist", idlist);
+
+ SendMessage(msg_block);
+ */
+
+ /*
+ // update contact details?
+ ClientNetMessage msg_persist;
+ msg_persist.add_int("persist", 1);
+ msg_persist.add_int("sesskey", sesskey);
+
+ msg_persist.add_int("cmd", 514);
+ msg_persist.add_int("dsn", 0);
+ msg_persist.add_int("uid", DBGetContactSettingDword(0, MODULE, "UID", 0));
+ msg_persist.add_int("lid", 9);
+ msg_persist.add_int("rid", req_id++);
+ char body[4096];
+ mir_snprintf(body, 4096, "ContactID=%d\x1cGroupName=\x1cPosition=1000\x1cVisibility=2\x1cNickName=\x1cNameSelect=0", mpsr->uid);
+ msg_persist.add_string("body", body);
+ SendMessage(msg_persist);
+ */
+
+ CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)MODULE);
+ }
+
+ return hContact;
+}
void SendMessage(ClientNetMessage &msg) {
char packet[4096];
@@ -121,7 +215,7 @@ void __cdecl ServerThreadFunc(void*) {
int conn_stat = ID_STATUS_CONNECTING;
QueueUserAPC(sttMainThreadStatusCallback, mainThread, conn_stat);
- server_running = true;
+ myspace_server_running = true;
char *recv_buffer = new char[SERVER_READ_BUFFER_SIZE];
int bytes = 0;
@@ -140,13 +234,13 @@ void __cdecl ServerThreadFunc(void*) {
bytes = Netlib_Recv(connection, (char *)recv_buffer, SERVER_READ_BUFFER_SIZE, MSG_DUMPASTEXT);
if(bytes == 0) {
- PUShowMessage("Connection closed", SM_NOTIFY);
+ //PUShowMessage("Connection closed", SM_NOTIFY);
if(login && tries < 9) {
conn_data.wPort = try_ports[tries++];
} else
break;
} else if(bytes == SOCKET_ERROR) {
- PUShowMessage("Socket ERROR", SM_NOTIFY);
+ //PUShowMessage("Socket ERROR", SM_NOTIFY);
if(login && tries < 9) {
conn_data.wPort = try_ports[tries++];
} else
@@ -159,129 +253,233 @@ void __cdecl ServerThreadFunc(void*) {
DBWriteContactSettingDword(0, MODULE, "LastPort", conn_data.wPort);
}
- //mir_snprintf(mt, 256, "recvd %d bytes", bytes);
- //PUShowMessage(mt, SM_NOTIFY);
+ char *pbuff = recv_buffer, *end;
+ while((end = strstr(pbuff, "\\final\\")) != 0) {
+ //mir_snprintf(mt, 256, "recvd %d bytes", bytes);
+ //PUShowMessage(mt, SM_NOTIFY);
+ if(pbuff != recv_buffer) {
+ PUShowMessage("Second packet", SM_NOTIFY);
+ }
+ end += 7;
+ *end = 0;
- NetMessage msg;
- msg.parse(recv_buffer, bytes);
- if(msg.exists(NMString("error"))) {
- char errmsg[256];
- if(msg.get_string("errmsg", errmsg, 256))
- PUShowMessage(errmsg, SM_WARNING);
- } else if(msg.get_int("lc") == 1) {
- QueueUserAPC(sttMainThreadStatusCallback, mainThread, conn_stat++);
- try_login(msg, server_connection);
- } else if(msg.get_int("lc") == 2) {
- sesskey = msg.get_int("sesskey");
- DBWriteContactSettingDword(0, MODULE, "UID", msg.get_int("userid"));
- char nick[256];
- if(msg.get_string("uniquenick", nick, 256))
- DBWriteContactSettingStringUtf(0, MODULE, "Nick", nick);
- QueueUserAPC(sttMainThreadStatusCallback, mainThread, ID_STATUS_ONLINE);
- } else if(msg.exists(NMString("persistr"))) {
-
- int cmd, dsn, lid, req;
- cmd = msg.get_int("cmd") & 255;
- dsn = msg.get_int("dsn");
- lid = msg.get_int("lid");
- req = msg.get_int("rid");
-
- mir_snprintf(mt, 256, "Peristr message: type is %d,%d,%d", cmd, dsn, lid);
- PUShowMessage(mt, SM_NOTIFY);
- if(cmd == 1 && dsn == 5 && lid == 7) {
- Dictionary body = msg.get_dict("body");
- char email[256], nick[256];
- int uid = body.get_int("UserID");
- if(uid != 0) {
- MYPROTOSEARCHRESULT mpsr = {sizeof(mpsr)};
-
- if(body.get_string("UserName", nick, 256))
- mpsr.psr.nick = nick;
- else if(body.get_string("DisplayName", nick, 256))
- mpsr.psr.nick = nick;
- if(body.get_string("Email", email, 256))
- mpsr.psr.email = email;
- mpsr.uid = uid;
-
- ProtoBroadcastAck(MODULE, 0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)req, (LPARAM)&mpsr);
- } else
- ProtoBroadcastAck(MODULE, 0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)req, 0);
- } else
- if(cmd == 1 && dsn == 4 && lid == 3) {
- Dictionary body = msg.get_dict("body");
+ NetMessage msg;
+ msg.parse(recv_buffer, bytes);
+ if(msg.exists(NMString("error"))) {
char errmsg[256];
- if(body.get_string("ErrorMessage", errmsg, 256)) {
+ if(msg.get_string("errmsg", errmsg, 256))
PUShowMessage(errmsg, SM_WARNING);
- ProtoBroadcastAck(MODULE, 0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)req, 0);
- } else {
+ } else if(msg.get_int("lc") == 1) {
+ QueueUserAPC(sttMainThreadStatusCallback, mainThread, conn_stat++);
+ try_login(msg, server_connection);
+ } else if(msg.get_int("lc") == 2) {
+ sesskey = msg.get_int("sesskey");
+ DBWriteContactSettingDword(0, MODULE, "UID", my_uid = msg.get_int("userid"));
+ char nick[256];
+ if(msg.get_string("uniquenick", nick, 256))
+ DBWriteContactSettingStringUtf(0, MODULE, "Nick", nick);
+ QueueUserAPC(sttMainThreadStatusCallback, mainThread, ID_STATUS_ONLINE);
+
+ if(my_uid == msg.get_int("uniquenick")) {
+ // need to pick a nick
+ ShowNickDialog();
+ }
+
+
+ // update our options on server
+ Dictionary d;
+ d.add_string("Sound", options.sound ? "True" : "False");
+ d.add_int("PrivacyMode", options.privacy_mode);
+ d.add_string("ShowOnlyToList", options.show_only_to_list ? "True" : "False");
+ d.add_int("OfflineMessageMode", options.offline_message_mode);
+ d.add_string("Headline", "");
+ d.add_int("Alert", 1);
+ d.add_string("ShowAvatar", options.show_avatar ? "True" : "False");
+ d.add_string("IMName", options.im_name);
+
+ ClientNetMessage cmsg;
+ cmsg.add_int("persist", 1);
+ cmsg.add_int("sesskey", sesskey);
+ cmsg.add_int("uid", DBGetContactSettingDword(0, MODULE, "UID", 0));
+ cmsg.add_int("cmd", 514);
+ cmsg.add_int("dsn", 1);
+ cmsg.add_int("lid", 10);
+ cmsg.add_int("rid", req_id++);
+ cmsg.add_dict("body", d);
+ SendMessage(cmsg);
+
+ // set blocklist
+ ClientNetMessage msg_block;
+ msg_block.add_string("blocklist", "");
+ msg_block.add_int("sesskey", sesskey);
+ msg_block.add_string("idlist", "w0|c0|a-|*|b-|*");
+ SendMessage(msg_block);
+
+ // set status
+ ClientNetMessage msg_status;
+ msg_status.add_int("status", stat_mir_to_myspace(signon_status));
+ msg_status.add_int("sesskey", sesskey);
+ msg_status.add_string("statstring", "");
+ msg_status.add_string("locstring", "");
+ SendMessage(msg_status);
+
+ /*
+ // set login time?
+ Dictionary ld;
+ ld.add_int("ContactType", 1);
+ ld.add_int("LastLogin", timestamp);
+ ClientNetMessage msg_setinfo;
+ msg_setinfo.add_string("setinfo", "");
+ msg_block.add_int("sesskey", sesskey);
+ msg_setinfo.add_dict("info", ld);
+ SendMessage(msg_setinfo);
+ */
+ } else if(msg.get_int("bm") == 100) { // status message
+ int uid = msg.get_int("f");
+ if(uid) {
+ HANDLE hContact = FindContact(uid);
+ if(!hContact) {
+ hContact = CreateContact(uid, 0, 0);
+ // lookup user?
+ }
+ char smsg[1024];
+ if(msg.get_string("msg", smsg, 1024)) {
+ DBWriteContactSettingWord(hContact, MODULE, "Status", stat_myspace_to_mir(smsg[3] - '0'));
+ }
+ }
+ } else if(msg.exists(NMString("persistr"))) {
+ int cmd, dsn, lid, req;
+ cmd = msg.get_int("cmd") & 255;
+ dsn = msg.get_int("dsn");
+ lid = msg.get_int("lid");
+ req = msg.get_int("rid");
+
+ mir_snprintf(mt, 256, "Peristr message: type is %d,%d,%d", cmd, dsn, lid);
+ PUShowMessage(mt, SM_NOTIFY);
+ if(cmd == 1 && dsn == 5 && lid == 7) { // userinfo (lookup by username/email)
+ Dictionary body = msg.get_dict("body");
char email[256], nick[256];
int uid = body.get_int("UserID");
+ if(nick_dialog) PostMessage(nick_dialog, WMU_NICKEXISTS, (WPARAM)(uid != 0), msg.get_int("rid"));
if(uid != 0) {
MYPROTOSEARCHRESULT mpsr = {sizeof(mpsr)};
- if(body.get_string("DisplayName", nick, 256))
+ if(body.get_string("UserName", nick, 256))
mpsr.psr.nick = nick;
- else if(body.get_string("UserName", nick, 256))
+ else if(body.get_string("DisplayName", nick, 256))
mpsr.psr.nick = nick;
-
if(body.get_string("Email", email, 256))
mpsr.psr.email = email;
mpsr.uid = uid;
ProtoBroadcastAck(MODULE, 0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)req, (LPARAM)&mpsr);
- } else
+ }
+ ProtoBroadcastAck(MODULE, 0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)req, 0);
+ } else
+ if(cmd == 1 && dsn == 4 && lid == 3) { // userinfo(lookup by userid)
+ Dictionary body = msg.get_dict("body");
+ char errmsg[256];
+ if(body.get_string("ErrorMessage", errmsg, 256)) {
+ PUShowMessage(errmsg, SM_WARNING);
ProtoBroadcastAck(MODULE, 0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)req, 0);
- }
- } else
- if(cmd == 2 && dsn == 0 && lid == 9) {
- Dictionary body = msg.get_dict("body");
- char errmsg[256];
- if(body.get_string("ErrorMessage", errmsg, 256)) {
- PUShowMessage(errmsg, SM_WARNING);
- } else {
- char nick[256];
- int uid = body.get_int("ContactID");
- if(uid != 0) {
- if(body.get_string("NickName", nick, 256)) {
- DBWriteContactSettingStringUtf(0, MODULE, "Nick", nick);
+ } else {
+ char email[256], nick[256];
+ int uid = body.get_int("UserID");
+ if(uid != 0) {
+ MYPROTOSEARCHRESULT mpsr = {sizeof(mpsr)};
+
+ if(body.get_string("DisplayName", nick, 256))
+ mpsr.psr.nick = nick;
+ else if(body.get_string("UserName", nick, 256))
+ mpsr.psr.nick = nick;
+
+ if(body.get_string("Email", email, 256))
+ mpsr.psr.email = email;
+ mpsr.uid = uid;
+
+ ProtoBroadcastAck(MODULE, 0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)req, (LPARAM)&mpsr);
}
+ ProtoBroadcastAck(MODULE, 0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)req, 0);
+ }
+ } else
+ if(cmd == 2 && dsn == 0 && lid == 9) {
+ Dictionary body = msg.get_dict("body");
+ char errmsg[256];
+ if(body.get_string("ErrorMessage", errmsg, 256)) {
+ PUShowMessage(errmsg, SM_WARNING);
+ } else {
+ char nick[256];
+ int uid = body.get_int("ContactID");
+ if(uid != 0) {
+ if(body.get_string("NickName", nick, 256)) {
+ DBWriteContactSettingStringUtf(0, MODULE, "Nick", nick);
+ }
+ }
+ }
+ } else
+ if(cmd == 2 && dsn == 9 && lid == 14) {
+ Dictionary body = msg.get_dict("body");
+ char errmsg[256];
+ if(body.get_string("ErrorMessage", errmsg, 256)) {
+ PUShowMessage(errmsg, SM_WARNING);
+ } else {
+ int code = body.get_int("Code");
+ if(nick_dialog) PostMessage(nick_dialog, WMU_CHANGEOK, (WPARAM)(code == 0), msg.get_int("rid"));
}
}
}
+ pbuff = end + 1;
}
}
}
if(server_connection) {
+ ClientNetMessage msg;
+ msg.add_string("logout", "");
+ msg.add_int("sesskey", sesskey);
+ SendMessage(msg);
Netlib_CloseHandle(server_connection);
server_connection = 0;
}
delete recv_buffer;
QueueUserAPC(sttMainThreadStatusCallback, mainThread, ID_STATUS_OFFLINE);
- server_running = false;
+ myspace_server_running = false;
+ SetAllOffline();
}
void StartThread() {
- if(!server_running) {
+ if(!myspace_server_running) {
server_stop = false;
mir_forkthread(ServerThreadFunc, 0);
}
}
void StopThread() {
- if(server_running) {
- server_stop = true;
- if(server_connection) {
- Netlib_CloseHandle(server_connection);
- server_connection = 0;
- }
+ if(myspace_server_running) {
+ ClientNetMessage msg;
+ msg.add_string("logout", "");
+ msg.add_int("sesskey", sesskey);
+ SendMessage(msg);
}
}
-void InitServerConnection() {
- StartThread();
-}
-
-void DeinitServerConnection() {
- StopThread();
+void SetServerStatus(int st) {
+ if(st == ID_STATUS_OFFLINE) {
+ StopThread();
+ } else {
+ if(myspace_server_running) {
+ // set status
+ ClientNetMessage msg_status;
+ msg_status.add_int("status", stat_mir_to_myspace(st));
+ msg_status.add_int("sesskey", sesskey);
+ msg_status.add_string("statstring", "");
+ msg_status.add_string("locstring", "");
+ SendMessage(msg_status);
+
+ QueueUserAPC(sttMainThreadStatusCallback, mainThread, st);
+ } else {
+ signon_status = st;
+ StartThread();
+ }
+ }
}
diff --git a/MySpace/server_con.h b/MySpace/server_con.h
index 9bbacf0..bbc0566 100644
--- a/MySpace/server_con.h
+++ b/MySpace/server_con.h
@@ -7,9 +7,13 @@
extern int status;
extern int sesskey;
extern int req_id;
+extern bool myspace_server_running;
+extern int my_uid;
-void InitServerConnection();
-void DeinitServerConnection();
+void SetServerStatus(int st);
+
+HANDLE FindContact(int uid);
+HANDLE CreateContact(int uid, char *nick, char *email);
void SendMessage(ClientNetMessage &msg);