summaryrefslogtreecommitdiff
path: root/MySpace/server_con.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'MySpace/server_con.cpp')
-rw-r--r--MySpace/server_con.cpp48
1 files changed, 41 insertions, 7 deletions
diff --git a/MySpace/server_con.cpp b/MySpace/server_con.cpp
index dbc7042..9f5a75d 100644
--- a/MySpace/server_con.cpp
+++ b/MySpace/server_con.cpp
@@ -6,6 +6,7 @@
#include "nick_dialog.h"
#include "formatting.h"
+#include <malloc.h>
#include <ctime>
#define SERVER_READ_BUFFER_SIZE (1024 * 32)
@@ -30,6 +31,7 @@ bool myspace_server_running = false, server_stop = false;
HANDLE server_connection = 0;
int sesskey = 0, req_id = 1, my_uid = 0;
int signon_status = ID_STATUS_ONLINE;
+char signon_status_msg[512] = {0};
int stat_mir_to_myspace(int mir_status) {
switch(mir_status) {
@@ -329,7 +331,7 @@ void __cdecl ServerThreadFunc(void*) {
char nick[256];
if(msg.get_string("uniquenick", nick, 256))
DBWriteContactSettingStringUtf(0, MODULE, "Nick", nick);
- QueueUserAPC(sttMainThreadStatusCallback, mainThread, ID_STATUS_ONLINE);
+ QueueUserAPC(sttMainThreadStatusCallback, mainThread, signon_status);
if(my_uid == msg.get_int("uniquenick")) {
// need to pick a nick
@@ -370,7 +372,7 @@ void __cdecl ServerThreadFunc(void*) {
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("statstring", signon_status_msg);
msg_status.add_string("locstring", "");
SendMessage(msg_status);
@@ -522,6 +524,7 @@ void __cdecl ServerThreadFunc(void*) {
ClientNetMessage msg;
msg.add_string("logout", "");
msg.add_int("sesskey", sesskey);
+ sesskey = 0;
SendMessage(msg);
Netlib_CloseHandle(server_connection);
server_connection = 0;
@@ -542,10 +545,17 @@ void StartThread() {
void StopThread() {
if(myspace_server_running) {
- ClientNetMessage msg;
- msg.add_string("logout", "");
- msg.add_int("sesskey", sesskey);
- SendMessage(msg);
+ if(sesskey) {
+ ClientNetMessage msg;
+ msg.add_string("logout", "");
+ msg.add_int("sesskey", sesskey);
+ SendMessage(msg);
+ } else {
+ if(server_connection) {
+ Netlib_CloseHandle(server_connection);
+ server_connection = 0;
+ }
+ }
}
}
@@ -553,7 +563,7 @@ void SetServerStatus(int st) {
if(st == ID_STATUS_OFFLINE) {
StopThread();
} else {
- if(myspace_server_running) {
+ if(myspace_server_running && sesskey) {
// set status
ClientNetMessage msg_status;
msg_status.add_int("status", stat_mir_to_myspace(st));
@@ -569,3 +579,27 @@ void SetServerStatus(int st) {
}
}
}
+
+void CALLBACK sttMainThreadStatusMessageCallback( ULONG dwParam ) {
+ char *msg = (char *)dwParam;
+ if(status != ID_STATUS_OFFLINE) {
+ if(myspace_server_running && sesskey) {
+ // set status
+ ClientNetMessage msg_status;
+ msg_status.add_int("status", stat_mir_to_myspace(status));
+ msg_status.add_int("sesskey", sesskey);
+ msg_status.add_string("statstring", msg ? msg : "");
+ msg_status.add_string("locstring", "");
+ SendMessage(msg_status);
+ } else {
+ if(msg) strncpy(signon_status_msg, msg, 512);
+ else signon_status_msg[0] = 0;
+ }
+ }
+ if(msg) free(msg);
+}
+
+void SetServerStatusMessage(char *msg) {
+ QueueUserAPC(sttMainThreadStatusMessageCallback, mainThread, (ULONG_PTR)(msg ? strdup(msg): 0));
+}
+