int GGPROTO::SendMsg(MCONTACT hContact, int, const char *msg) { uin_t uin = (uin_t)getDword(hContact, GG_KEY_UIN, 0); if (!isonline() || !uin) return 0; if (!msg) return 0; gg_EnterCriticalSection(&sess_mutex, "SendMsg", 53, "sess_mutex", 1); int seq = gg_send_message(sess, GG_CLASS_CHAT, uin, (BYTE*)msg); gg_LeaveCriticalSection(&sess_mutex, "SendMsg", 53, 1, "sess_mutex", 1); if (!getByte(GG_KEY_MSGACK, GG_KEYDEF_MSGACK)) { // Auto-ack message without waiting for server ack GG_SEQ_ACK *ack = (GG_SEQ_ACK*)mir_alloc(sizeof(GG_SEQ_ACK)); if (ack) { ack->seq = seq; ack->hContact = hContact; #ifdef DEBUGMODE debugLogA("SendMsg(): ForkThread 16 GGPROTO::sendackthread"); #endif ForkThread(&GGPROTO::sendackthread, ack); } } return seq; }
HANDLE GGPROTO::SearchBasic(const TCHAR *id) { if (!isonline()) return 0; gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_SEARCH); if (!req) { #ifdef DEBUGMODE debugLogA("SearchBasic(): ForkThread 10 GGPROTO::searchthread"); #endif ForkThread(&GGPROTO::searchthread, NULL); return (HANDLE)1; } // Add uin and search it gg_pubdir50_add(req, GG_PUBDIR50_UIN, T2Utf(id)); gg_pubdir50_seq_set(req, GG_SEQ_SEARCH); gg_EnterCriticalSection(&sess_mutex, "SearchBasic", 50, "sess_mutex", 1); if (!gg_pubdir50(sess, req)) { gg_LeaveCriticalSection(&sess_mutex, "SearchBasic", 50, 1, "sess_mutex", 1); #ifdef DEBUGMODE debugLogA("SearchBasic(): ForkThread 11 GGPROTO::searchthread"); #endif ForkThread(&GGPROTO::searchthread, NULL); return (HANDLE)1; } gg_LeaveCriticalSection(&sess_mutex, "SearchBasic", 50, 2, "sess_mutex", 1); debugLogA("SearchBasic(): Seq %d.", req->seq); gg_pubdir50_free(req); return (HANDLE)1; }
INT_PTR GGPROTO::getmyawaymsg(WPARAM wParam, LPARAM lParam) { INT_PTR res = 0; gg_EnterCriticalSection(&modemsg_mutex, "refreshstatus", 72, "modemsg_mutex", 1); TCHAR *szMsg = getstatusmsg(wParam ? gg_normalizestatus(wParam) : m_iStatus); if (isonline() && szMsg) res = (lParam & SGMA_UNICODE) ? (INT_PTR)mir_t2u(szMsg) : (INT_PTR)mir_t2a(szMsg); gg_LeaveCriticalSection(&modemsg_mutex, "refreshstatus", 72, 1, "modemsg_mutex", 1); return res; }
char* queenlooper(char* square){ int count = 0; int foundx = 0; int foundy = 0; int x = squarexfinder(square); int y = squareyfinder(square); int i = j = 0; for (i = 0; i < 8; i++){ for (j = 0; j < 8; j++){ char* status = board[i][j]; if (wturn == 1 && status == "Qw" && isbetween(square, map[i][j]) == 0 && (isonline(square, map[i][j]) == 1 || isondiag(square, map[i][j]) == 1)){ count++; foundx = i; foundy = j; } else if (wturn == 0 && status == "Qb" && isbetween(square, map[i][j]) == 0 && (isonline(square, map[i][j]) == 1 || isondiag(square, map[i][j]) == 1)){ count++; foundx = i; foundy = j; } } } if (count == 0) return "-1"; else if (count == 1) return map[foundx][foundy]; else if (count > 1) return "0"; }
int GGPROTO::refreshstatus(int status) { if (status == ID_STATUS_OFFLINE) { disconnect(); return TRUE; } if (!isonline()) { DWORD exitCode = 0; GetExitCodeThread(pth_sess.hThread, &exitCode); if (exitCode == STILL_ACTIVE) return TRUE; #ifdef DEBUGMODE debugLogA("refreshstatus(): Waiting pth_sess thread. Going to connect..."); #endif threadwait(&pth_sess); #ifdef DEBUGMODE debugLogA("refreshstatus(): Waiting pth_sess thread - OK"); debugLogA("refreshstatus(): ForkThreadEx 21 GGPROTO::mainthread"); #endif pth_sess.hThread = ForkThreadEx(&GGPROTO::mainthread, NULL, &pth_sess.dwThreadId); } else { TCHAR *szMsg = NULL; // Select proper msg gg_EnterCriticalSection(&modemsg_mutex, "refreshstatus", 69, "modemsg_mutex", 1); szMsg = getstatusmsg(status); gg_LeaveCriticalSection(&modemsg_mutex, "refreshstatus", 69, 1, "modemsg_mutex", 1); T2Utf szMsg_utf8(szMsg); if (szMsg_utf8) { debugLogA("refreshstatus(): Setting status and away message."); gg_EnterCriticalSection(&sess_mutex, "refreshstatus", 70, "sess_mutex", 1); gg_change_status_descr(sess, status_m2gg(status, szMsg_utf8 != NULL), szMsg_utf8); gg_LeaveCriticalSection(&sess_mutex, "refreshstatus", 70, 1, "sess_mutex", 1); } else { debugLogA("refreshstatus(): Setting just status."); gg_EnterCriticalSection(&sess_mutex, "refreshstatus", 71, "sess_mutex", 1); gg_change_status(sess, status_m2gg(status, 0)); gg_LeaveCriticalSection(&sess_mutex, "refreshstatus", 71, 1, "sess_mutex", 1); } // Change status of the contact with our own UIN (if got yourself added to the contact list) changecontactstatus( getDword(GG_KEY_UIN, 0), status_m2gg(status, szMsg != NULL), szMsg, 0, 0, 0, 0); broadcastnewstatus(status); } return TRUE; }
int GGPROTO::UserIsTyping(HANDLE hContact, int type) { uin_t uin = getDword(hContact, GG_KEY_UIN, 0); if (!uin || !isonline()) return 0; if (type == PROTOTYPE_SELFTYPING_ON || type == PROTOTYPE_SELFTYPING_OFF) { gg_EnterCriticalSection(&sess_mutex, "UserIsTyping", 56, "sess_mutex", 1); gg_typing_notification(sess, uin, (type == PROTOTYPE_SELFTYPING_ON)); gg_LeaveCriticalSection(&sess_mutex, "UserIsTyping", 56, 1, "sess_mutex", 1); } return 0; }
INT_PTR GGPROTO::gc_openconf(WPARAM, LPARAM) { // Check if connected if (!isonline()) { MessageBox(NULL, TranslateT("You have to be connected to open new conference."), m_tszUserName, MB_OK | MB_ICONSTOP ); return 0; } CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_CONFERENCE), NULL, gg_gc_openconfdlg, (LPARAM)this); return 1; }
int arraydistance(char* to, char* from){ int fromx = squarexfinder(from); int fromy = squareyfinder(from); int tox = squarexfinder(to); int toy = squareyfinder(to); if (isonline(to, from) == 1) return abs((fromx - tox) + (toy - fromy)); else if (isondiag(to, from) == 1) return abs(tox - fromx); else return -1; }
int GGPROTO::SendMsg(HANDLE hContact, int flags, const char *msg) { uin_t uin = (uin_t)getDword(hContact, GG_KEY_UIN, 0); if (!isonline() || !uin) return 0; char* msg_utf8; if (flags & PREF_UNICODE) msg_utf8 = mir_utf8encodeW((wchar_t*)&msg[ strlen( msg )+1 ] ); else if (flags & PREF_UTF) msg_utf8 = mir_strdup(msg); else msg_utf8 = mir_utf8encode(msg); if (!msg_utf8) return 0; gg_EnterCriticalSection(&sess_mutex, "SendMsg", 53, "sess_mutex", 1); int seq = gg_send_message(sess, GG_CLASS_CHAT, uin, (BYTE*)msg_utf8); gg_LeaveCriticalSection(&sess_mutex, "SendMsg", 53, 1, "sess_mutex", 1); if (!getByte(GG_KEY_MSGACK, GG_KEYDEF_MSGACK)) { // Auto-ack message without waiting for server ack GG_SEQ_ACK *ack = (GG_SEQ_ACK*)mir_alloc(sizeof(GG_SEQ_ACK)); if (ack) { ack->seq = seq; ack->hContact = hContact; #ifdef DEBUGMODE debugLogA("SendMsg(): ForkThread 16 GGPROTO::sendackthread"); #endif ForkThread(&GGPROTO::sendackthread, ack); } } mir_free(msg_utf8); return seq; }
HANDLE GGPROTO::SendFile(MCONTACT hContact, const TCHAR* szDescription, TCHAR** ppszFiles) { char *bslash, *filename; DWORD ip, ver; WORD port; uin_t myuin, uin; // Check if main dcc thread is on if (!isonline()) return ftfail(this, hContact); filename = mir_t2a(ppszFiles[0]); // Read user IP and port ip = swap32(getDword(hContact, GG_KEY_CLIENTIP, 0)); port = getWord(hContact, GG_KEY_CLIENTPORT, 0); myuin = getDword(GG_KEY_UIN, 0); uin = getDword(hContact, GG_KEY_UIN, 0); ver = getDword(hContact, GG_KEY_CLIENTVERSION, 0); // Use DCC7 if a contact is using at least version 7.6 or unknown version if ((ver & 0x00ffffff) >= 0x29 || !ver) { gg_EnterCriticalSection(&sess_mutex, "SendFile", 46, "sess_mutex", 1); struct gg_dcc7 *dcc7 = gg_dcc7_send_file(sess, uin, filename, NULL, NULL); if (!dcc7) { gg_LeaveCriticalSection(&sess_mutex, "SendFile", 46, 1, "sess_mutex", 1); debugLogA("SendFile(): Failed to send file \"%s\".", filename); mir_free(filename); return ftfail(this, hContact); } gg_LeaveCriticalSection(&sess_mutex, "SendFile", 46, 2, "sess_mutex", 1); debugLogA("SendFile(): Sending file \"%s\" to %d.", filename, uin); // Add dcc to watches list_add(&watches, dcc7, 0); // Store handle dcc7->contact = (void*)hContact; dcc7->folder = _strdup(filename); dcc7->tick = 0; // Make folder name bslash = strrchr(dcc7->folder, '\\'); if (bslash) *(bslash + 1) = 0; else *(dcc7->folder) = 0; mir_free(filename); return dcc7; } // Return if bad connection info if (!port || !uin || !myuin) { debugLogA("SendFile(): Bad contact uin or my uin. Exit."); mir_free(filename); return ftfail(this, hContact); } // Try to connect if not ask user to connect me struct gg_dcc *dcc = NULL; if ((ip && port >= 10 && !(dcc = gg_dcc_send_file(ip, port, myuin, uin))) || (port < 10 && port > 0)) { // Make fake dcc structure dcc = (gg_dcc*)malloc(sizeof(struct gg_dcc)); memset(dcc, 0, sizeof(struct gg_dcc)); // Fill up structures dcc->uin = myuin; dcc->peer_uin = uin; dcc->fd = -1; dcc->type = GG_SESSION_DCC_SEND; debugLogA("SendFile(): Requesting user to connect us and scheduling gg_dcc struct for a later use."); gg_EnterCriticalSection(&sess_mutex, "SendFile", 47, "sess_mutex", 1); gg_dcc_request(sess, uin); gg_LeaveCriticalSection(&sess_mutex, "SendFile", 47, 1, "sess_mutex", 1); list_add(&requests, dcc, 0); } // Write filename if (gg_dcc_fill_file_info(dcc, filename) == -1) { debugLogA("SendFile(): Cannot open and file fileinfo \"%s\".", filename); gg_free_dcc(dcc); mir_free(filename); return ftfail(this, hContact); } debugLogA("SendFile(): Sending file \"%s\" to %d in %s mode.", filename, uin, (dcc->fd != -1) ? "active" : "passive"); // Add dcc to watches if not passive if (dcc->fd != -1) list_add(&watches, dcc, 0); // Store handle dcc->contact = (void*)hContact; dcc->folder = _strdup(filename); dcc->tick = 0; // Make folder name bslash = strrchr(dcc->folder, '\\'); if (bslash) *(bslash + 1) = 0; else *(dcc->folder) = 0; mir_free(filename); return dcc; }
int GGPROTO::gc_event(WPARAM, LPARAM lParam) { GCHOOK *gch = (GCHOOK *)lParam; GGGC *chat = NULL; uin_t uin; // Check if we got our protocol, and fields are set if (!gch || !gch->pDest || !gch->pDest->ptszID || !gch->pDest->pszModule || mir_strcmpi(gch->pDest->pszModule, m_szModuleName) || !(uin = getDword(GG_KEY_UIN, 0)) || !(chat = gc_lookup(gch->pDest->ptszID))) return 0; // Window terminated (Miranda exit) if (gch->pDest->iType == SESSION_TERMINATE) { debugLog(_T("gc_event(): Terminating chat %x, id %s from chat window..."), chat, gch->pDest->ptszID); // Destroy chat entry free(chat->recipients); list_remove(&chats, chat, 1); // Remove contact from contact list (duh!) should be done by chat.dll !! for (MCONTACT hContact = db_find_first(); hContact; ) { MCONTACT hNext = db_find_next(hContact); DBVARIANT dbv; if (!getTString(hContact, "ChatRoomID", &dbv)) { if (dbv.ptszVal && !mir_tstrcmp(gch->pDest->ptszID, dbv.ptszVal)) CallService(MS_DB_CONTACT_DELETE, hContact, 0); db_free(&dbv); } hContact = hNext; } return 1; } // Message typed / send only if online if (isonline() && (gch->pDest->iType == GC_USER_MESSAGE) && gch->ptszText) { TCHAR id[32]; UIN2IDT(uin, id); DBVARIANT dbv; GCDEST gcd = { m_szModuleName, gch->pDest->ptszID, GC_EVENT_MESSAGE }; GCEVENT gce = { sizeof(gce), &gcd }; gce.ptszUID = id; gce.ptszText = gch->ptszText; TCHAR* nickT; if (!getTString(GG_KEY_NICK, &dbv)){ nickT = mir_tstrdup(dbv.ptszVal); db_free(&dbv); } else nickT = mir_tstrdup(TranslateT("Me")); gce.ptszNick = nickT; // Get rid of CRLF at back int lc = (int)mir_tstrlen(gch->ptszText) - 1; while(lc >= 0 && (gch->ptszText[lc] == '\n' || gch->ptszText[lc] == '\r')) gch->ptszText[lc --] = 0; gce.time = time(NULL); gce.bIsMe = 1; gce.dwFlags = GCEF_ADDTOLOG; debugLog(_T("gc_event(): Sending conference message to room %s, \"%s\"."), gch->pDest->ptszID, gch->ptszText); CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); mir_free(nickT); T2Utf pszText_utf8(gch->ptszText); gg_EnterCriticalSection(&sess_mutex, "gc_event", 57, "sess_mutex", 1); gg_send_message_confer(sess, GG_CLASS_CHAT, chat->recipients_count, chat->recipients, pszText_utf8); gg_LeaveCriticalSection(&sess_mutex, "gc_event", 57, 1, "sess_mutex", 1); return 1; } // Privmessage selected if (gch->pDest->iType == GC_USER_PRIVMESS) { MCONTACT hContact = NULL; if ((uin = _ttoi(gch->ptszUID)) && (hContact = getcontact(uin, 1, 0, NULL))) CallService(MS_MSG_SENDMESSAGE, hContact, 0); } debugLog(_T("gc_event(): Unhandled event %d, chat %x, uin %d, text \"%s\"."), gch->pDest->iType, chat, uin, gch->ptszText); return 0; }
HWND GGPROTO::SearchAdvanced(HWND hwndDlg) { gg_pubdir50_t req; TCHAR text[64]; char data[800] = "\0"; unsigned long crc; // Check if connected if (!isonline()) return (HWND)0; if (!(req = gg_pubdir50_new(GG_PUBDIR50_SEARCH))) { #ifdef DEBUGMODE debugLogA("SearchAdvanced(): ForkThread 14 GGPROTO::searchthread"); #endif ForkThread(&GGPROTO::searchthread, NULL); return (HWND)1; } // Fetch search data GetDlgItemText(hwndDlg, IDC_FIRSTNAME, text, sizeof(text)); if (_tcslen(text)) { char *firstName_utf8 = mir_utf8encodeT(text); gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, firstName_utf8); strncat(data, firstName_utf8, sizeof(data) - strlen(data)); mir_free(firstName_utf8); } /* 1 */ strncat(data, ".", sizeof(data) - strlen(data)); GetDlgItemText(hwndDlg, IDC_LASTNAME, text, sizeof(text)); if (_tcslen(text)) { char *lastName_utf8 = mir_utf8encodeT(text); gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, lastName_utf8); strncat(data, lastName_utf8, sizeof(data) - strlen(data)); mir_free(lastName_utf8); } /* 2 */ strncat(data, ".", sizeof(data) - strlen(data)); GetDlgItemText(hwndDlg, IDC_NICKNAME, text, sizeof(text)); if (_tcslen(text)) { char *nickName_utf8 = mir_utf8encodeT(text); gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, nickName_utf8); strncat(data, nickName_utf8, sizeof(data) - strlen(data)); mir_free(nickName_utf8); } /* 3 */ strncat(data, ".", sizeof(data) - strlen(data)); GetDlgItemText(hwndDlg, IDC_CITY, text, sizeof(text)); if (_tcslen(text)) { char *city_utf8 = mir_utf8encodeT(text); gg_pubdir50_add(req, GG_PUBDIR50_CITY, city_utf8); strncat(data, city_utf8, sizeof(data) - strlen(data)); mir_free(city_utf8); } /* 4 */ strncat(data, ".", sizeof(data) - strlen(data)); GetDlgItemText(hwndDlg, IDC_AGEFROM, text, sizeof(text)); if (_tcslen(text)) { int yearTo = _tstoi(text); int yearFrom; time_t t = time(NULL); struct tm *lt = localtime(&t); int ay = lt->tm_year + 1900; char age[16]; GetDlgItemTextA(hwndDlg, IDC_AGETO, age, sizeof(age)); yearFrom = atoi(age); // Count & fix ranges if (!yearTo) yearTo = ay; else yearTo = ay - yearTo; if (!yearFrom) yearFrom = 0; else yearFrom = ay - yearFrom; mir_sntprintf(text, sizeof(text), _T("%d %d"), yearFrom, yearTo); char *age_utf8 = mir_utf8encodeT(text); gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, age_utf8); strncat(data, age_utf8, sizeof(data) - strlen(data)); mir_free(age_utf8); } /* 5 */ strncat(data, ".", sizeof(data) - strlen(data)); switch(SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_GETCURSEL, 0, 0)) { case 1: gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_FEMALE); strncat(data, GG_PUBDIR50_GENDER_MALE, sizeof(data) - strlen(data)); break; case 2: gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_MALE); strncat(data, GG_PUBDIR50_GENDER_FEMALE, sizeof(data) - strlen(data)); break; } /* 6 */ strncat(data, ".", sizeof(data) - strlen(data)); if (IsDlgButtonChecked(hwndDlg, IDC_ONLYCONNECTED)) { gg_pubdir50_add(req, GG_PUBDIR50_ACTIVE, GG_PUBDIR50_ACTIVE_TRUE); strncat(data, GG_PUBDIR50_ACTIVE_TRUE, sizeof(data) - strlen(data)); } /* 7 */ strncat(data, ".", sizeof(data) - strlen(data)); // No data entered if (strlen(data) <= 7 || (strlen(data) == 8 && IsDlgButtonChecked(hwndDlg, IDC_ONLYCONNECTED))) return (HWND)0; // Count crc & check if the data was equal if yes do same search with shift crc = crc_get(data); if (crc == last_crc && next_uin) gg_pubdir50_add(req, GG_PUBDIR50_START, ditoa(next_uin)); else last_crc = crc; gg_pubdir50_seq_set(req, GG_SEQ_SEARCH); if (isonline()) { gg_EnterCriticalSection(&sess_mutex, "SearchAdvanced", 52, "sess_mutex", 1); if (!gg_pubdir50(sess, req)) { gg_LeaveCriticalSection(&sess_mutex, "SearchAdvanced", 52, 1, "sess_mutex", 1); #ifdef DEBUGMODE debugLogA("SearchAdvanced(): ForkThread 15 GGPROTO::searchthread"); #endif ForkThread(&GGPROTO::searchthread, NULL); return (HWND)1; } gg_LeaveCriticalSection(&sess_mutex, "SearchAdvanced", 52, 2, "sess_mutex", 1); } debugLogA("SearchAdvanced(): Seq %d.", req->seq); gg_pubdir50_free(req); return (HWND)1; }
HANDLE GGPROTO::SearchByName(const PROTOCHAR *nick, const PROTOCHAR *firstName, const PROTOCHAR *lastName) { gg_pubdir50_t req; unsigned long crc; char data[512] = "\0"; // Check if connected and if there's a search data if (!isonline()) return 0; if (!nick && !firstName && !lastName) return 0; if (!(req = gg_pubdir50_new(GG_PUBDIR50_SEARCH))) { #ifdef DEBUGMODE debugLogA("SearchByName(): ForkThread 12 GGPROTO::searchthread"); #endif ForkThread(&GGPROTO::searchthread, NULL); return (HANDLE)1; } // Add nick,firstName,lastName and search it if (nick) { char *nick_utf8 = mir_utf8encodeT(nick); gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, nick_utf8); strncat(data, nick_utf8, sizeof(data) - strlen(data)); mir_free(nick_utf8); } strncat(data, ".", sizeof(data) - strlen(data)); if (firstName) { char *firstName_utf8 = mir_utf8encodeT(firstName); gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, firstName_utf8); strncat(data, firstName_utf8, sizeof(data) - strlen(data)); mir_free(firstName_utf8); } strncat(data, ".", sizeof(data) - strlen(data)); if (lastName) { char *lastName_utf8 = mir_utf8encodeT(lastName); gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, lastName_utf8); strncat(data, lastName_utf8, sizeof(data) - strlen(data)); mir_free(lastName_utf8); } strncat(data, ".", sizeof(data) - strlen(data)); // Count crc & check if the data was equal if yes do same search with shift crc = crc_get(data); if (crc == last_crc && next_uin) gg_pubdir50_add(req, GG_PUBDIR50_START, ditoa(next_uin)); else last_crc = crc; gg_pubdir50_seq_set(req, GG_SEQ_SEARCH); gg_EnterCriticalSection(&sess_mutex, "SearchByName", 51, "sess_mutex", 1); if (!gg_pubdir50(sess, req)) { gg_LeaveCriticalSection(&sess_mutex, "SearchByName", 51, 1, "sess_mutex", 1); #ifdef DEBUGMODE debugLogA("SearchByName(): ForkThread 13 GGPROTO::searchthread"); #endif ForkThread(&GGPROTO::searchthread, NULL); return (HANDLE)1; } gg_LeaveCriticalSection(&sess_mutex, "SearchByName", 51, 2, "sess_mutex", 1); debugLogA("SearchByName(): Seq %d.", req->seq); gg_pubdir50_free(req); return (HANDLE)1; }
int GGPROTO::GetInfo(HANDLE hContact, int infoType) { gg_pubdir50_t req; // Custom contact info if (hContact) { if (!(req = gg_pubdir50_new(GG_PUBDIR50_SEARCH))) { #ifdef DEBUGMODE debugLogA("GetInfo(): ForkThread 6 GGPROTO::cmdgetinfothread"); #endif ForkThread(&GGPROTO::cmdgetinfothread, hContact); return 1; } // Add uin and search it gg_pubdir50_add(req, GG_PUBDIR50_UIN, ditoa((uin_t)getDword(hContact, GG_KEY_UIN, 0))); gg_pubdir50_seq_set(req, GG_SEQ_INFO); debugLogA("GetInfo(): Requesting user info.", req->seq); if (isonline()) { gg_EnterCriticalSection(&sess_mutex, "GetInfo", 48, "sess_mutex", 1); if (!gg_pubdir50(sess, req)) { gg_LeaveCriticalSection(&sess_mutex, "GetInfo", 48, 1, "sess_mutex", 1); #ifdef DEBUGMODE debugLogA("GetInfo(): ForkThread 7 GGPROTO::cmdgetinfothread"); #endif ForkThread(&GGPROTO::cmdgetinfothread, hContact); return 1; } gg_LeaveCriticalSection(&sess_mutex, "GetInfo", 48, 2, "sess_mutex", 1); } } // Own contact info else { if (!(req = gg_pubdir50_new(GG_PUBDIR50_READ))) { #ifdef DEBUGMODE debugLogA("GetInfo(): ForkThread 8 GGPROTO::cmdgetinfothread"); #endif ForkThread(&GGPROTO::cmdgetinfothread, hContact); return 1; } // Add seq gg_pubdir50_seq_set(req, GG_SEQ_CHINFO); debugLogA("GetInfo(): Requesting owner info.", req->seq); if (isonline()) { gg_EnterCriticalSection(&sess_mutex, "GetInfo", 49, "sess_mutex", 1); if (!gg_pubdir50(sess, req)) { gg_LeaveCriticalSection(&sess_mutex, "GetInfo", 49, 1, "sess_mutex", 1); #ifdef DEBUGMODE debugLogA("GetInfo(): ForkThread 9 GGPROTO::cmdgetinfothread"); #endif ForkThread(&GGPROTO::cmdgetinfothread, hContact); return 1; } gg_LeaveCriticalSection(&sess_mutex, "GetInfo", 49, 2, "sess_mutex", 1); } } debugLogA("GetInfo(): Seq %d.", req->seq); gg_pubdir50_free(req); return 1; }
HANDLE GGPROTO::SearchByName(const TCHAR *nick, const TCHAR *firstName, const TCHAR *lastName) { // Check if connected and if there's a search data if (!isonline()) return 0; if (!nick && !firstName && !lastName) return 0; gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_SEARCH); if (req == NULL) { #ifdef DEBUGMODE debugLogA("SearchByName(): ForkThread 12 GGPROTO::searchthread"); #endif ForkThread(&GGPROTO::searchthread, NULL); return (HANDLE)1; } // Add nick,firstName,lastName and search it CMStringA szQuery; if (nick) { T2Utf nick_utf8(nick); gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, nick_utf8); szQuery.Append(nick_utf8); } szQuery.AppendChar('.'); if (firstName) { T2Utf firstName_utf8(firstName); gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, firstName_utf8); szQuery.Append(firstName_utf8); } szQuery.AppendChar('.'); if (lastName) { T2Utf lastName_utf8(lastName); gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, lastName_utf8); szQuery.Append(lastName_utf8); } szQuery.AppendChar('.'); // Count crc & check if the data was equal if yes do same search with shift unsigned long crc = crc_get(szQuery.GetBuffer()); if (crc == last_crc && next_uin) gg_pubdir50_add(req, GG_PUBDIR50_START, ditoa(next_uin)); else last_crc = crc; gg_pubdir50_seq_set(req, GG_SEQ_SEARCH); gg_EnterCriticalSection(&sess_mutex, "SearchByName", 51, "sess_mutex", 1); if (!gg_pubdir50(sess, req)) { gg_LeaveCriticalSection(&sess_mutex, "SearchByName", 51, 1, "sess_mutex", 1); #ifdef DEBUGMODE debugLogA("SearchByName(): ForkThread 13 GGPROTO::searchthread"); #endif ForkThread(&GGPROTO::searchthread, NULL); return (HANDLE)1; } gg_LeaveCriticalSection(&sess_mutex, "SearchByName", 51, 2, "sess_mutex", 1); debugLogA("SearchByName(): Seq %d.", req->seq); gg_pubdir50_free(req); return (HANDLE)1; }
bool isbetween(char* to, char* from) { int fromx = squarexfinder(from); int fromy = squareyfinder(from); int tox = squarexfinder(to); int toy = squareyfinder(to); if (isondiag(to,from) == 1 && tox < fromx && toy < fromy) { if (diaglooper(tox, toy, fromx, 0) == 1) return 1; else return 0; } else if (isondiag(to,from) == 1 && fromx < tox && fromy < toy) { if (diaglooper(fromx, fromy, tox, 0) == 1) return 1; else return 0; } else if (isondiag(to,from) == 1 && tox > fromx && fromy > toy) { if (diaglooper(tox, toy, fromx, 1) == 1) return 1; else return 0; } else if (isondiag(to,from) == 1 && tox < fromx && toy > fromy) { if (diaglooper(fromx, fromy, tox, 1) == 1) return 1; else return 0; } else if (isonline(to,from) == 1 && fromx > tox) { if (linelooper(tox, toy, fromx, 0) == 1) return 1; else { printf("Nothing found between %s and %s\n", to, from); return 0; } } else if (isonline(to,from) == 1 && tox > fromx) { if (linelooper(fromx, toy, tox, 0) == 1) return 1; else return 0; } else if (isonline(to,from) == 1 && fromy > toy){ if (linelooper(tox, fromy, toy, 1) == 1) return 1; else return 0; } else if (isonline(to,from) == 1 && toy > fromy) { if (linelooper(tox, toy, fromy, 1) == 1) return 1; else return 0; } else printf("%s and %s are not on the same line or diagonal\n", to, from); }
bool checkcheck(int kingx, int kingy) { if (kingx == -1) { kingx = kingfinder(0); kingy = kingfinder(1); } if (wturn == 1) { int i, j; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { if (isonline(map[kingx][kingy], map[i][j]) == 1 && isbetween(map[kingx][kingy], map[i][j]) == 0 && (board[i][j] == "Qb" || board[i][j] == "Rb")) { return 1; } if (isondiag(map[kingx][kingy], map[i][j]) == 1 && isbetween(map[kingx][kingy], map[i][j]) == 0 && (board[i][j] == "Qb" || board[i][j] == "Bb")) { return 1; } if (board[kingx-1][kingy-1] == "pb") { return 1; } if (board[kingx-1][kingy+1] == "pb") { return 1; } if (arraydistance(map[kingx][kingy], map[i][j]) == 1 && board[i][j] == "Kb") { return 1; } if (knightlooper(map[kingx][kingy], "Nb") != "0") { return 1; } } } return 0; } else if (wturn == 0) { int i, j; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { if (isonline(map[kingx][kingy], map[i][j]) == 1 && isbetween(map[kingx][kingy], map[i][j]) == 0 && (board[i][j] == "Qw" || board[i][j] == "Rw")) return 1; if (isondiag(map[kingx][kingy], map[i][j]) == 1 && isbetween(map[kingx][kingy], map[i][j]) == 0 && (board[i][j] == "Qw" || board[i][j] == "Bw")) return 1; if (board[kingx+1][kingy-1] == "pw" || board[kingx+1][kingy+1] == "pw") return 1; if (arraydistance(map[kingx][kingy], map[i][j]) == 1 && board[i][j] == "Kw") return 1; if (knightlooper(map[kingx][kingy], "Nw") != "0") return 1; } } return 0; } }