void TwitterProto::MessageLoop(void*) { LOG("***** Entering Twitter::MessageLoop"); since_id_ = db_pod_get<twitter_id>(0,m_szModuleName,TWITTER_KEY_SINCEID,0); dm_since_id_ = db_pod_get<twitter_id>(0,m_szModuleName,TWITTER_KEY_DMSINCEID,0); bool new_account = db_byte_get(0,m_szModuleName,TWITTER_KEY_NEW,1) != 0; bool popups = db_byte_get(0,m_szModuleName,TWITTER_KEY_POPUP_SIGNON,1) != 0; int poll_rate = db_dword_get(0,m_szModuleName,TWITTER_KEY_POLLRATE,80); for(unsigned int i=0;;i++) { if(m_iStatus != ID_STATUS_ONLINE) goto exit; if(i%4 == 0) UpdateFriends(); if(m_iStatus != ID_STATUS_ONLINE) goto exit; UpdateStatuses(new_account,popups); if(m_iStatus != ID_STATUS_ONLINE) goto exit; UpdateMessages(new_account); if(new_account) // Not anymore! { new_account = false; DBWriteContactSettingByte(0,m_szModuleName,TWITTER_KEY_NEW,0); } if(m_iStatus != ID_STATUS_ONLINE) goto exit; LOG("***** TwitterProto::MessageLoop going to sleep..."); if(SleepEx(poll_rate*1000,true) == WAIT_IO_COMPLETION) goto exit; LOG("***** TwitterProto::MessageLoop waking up..."); popups = true; } exit: { ScopedLock s(twitter_lock_); twit_.set_credentials("","",false); } LOG("***** Exiting TwitterProto::MessageLoop"); }
int ParseEPD (char *p) /************************************************************************** * * Parses an EPD input line. A few global variables are updated e.g. * current board, side to move, en passant, castling status, etc. * **************************************************************************/ { int r, c, sq; char *str_p; r = 56; c = 0; memset (&board, 0, sizeof (board)); while (p && *p != ' ') { sq = r + c; switch (*p) { case 'P' : SETBIT (board.b[white][pawn], sq); SETBIT (board.blockerr90, r90[sq]); SETBIT (board.blockerr45, r45[sq]); SETBIT (board.blockerr315, r315[sq]); board.material[white] += ValueP; break; case 'N' : SETBIT (board.b[white][knight], sq); SETBIT (board.blockerr90, r90[sq]); SETBIT (board.blockerr45, r45[sq]); SETBIT (board.blockerr315, r315[sq]); board.material[white] += ValueN; break; case 'B' : SETBIT (board.b[white][bishop], sq); SETBIT (board.blockerr90, r90[sq]); SETBIT (board.blockerr45, r45[sq]); SETBIT (board.blockerr315, r315[sq]); board.material[white] += ValueB; break; case 'R' : SETBIT (board.b[white][rook], sq); SETBIT (board.blockerr90, r90[sq]); SETBIT (board.blockerr45, r45[sq]); SETBIT (board.blockerr315, r315[sq]); board.material[white] += ValueR; break; case 'Q' : SETBIT (board.b[white][queen], sq); SETBIT (board.blockerr90, r90[sq]); SETBIT (board.blockerr45, r45[sq]); SETBIT (board.blockerr315, r315[sq]); board.material[white] += ValueQ; break; case 'K' : SETBIT (board.b[white][king], sq); SETBIT (board.blockerr90, r90[sq]); SETBIT (board.blockerr45, r45[sq]); SETBIT (board.blockerr315, r315[sq]); break; case 'p' : SETBIT (board.b[black][pawn], sq); SETBIT (board.blockerr90, r90[sq]); SETBIT (board.blockerr45, r45[sq]); SETBIT (board.blockerr315, r315[sq]); board.material[black] += ValueP; break; case 'n' : SETBIT (board.b[black][knight], sq); SETBIT (board.blockerr90, r90[sq]); SETBIT (board.blockerr45, r45[sq]); SETBIT (board.blockerr315, r315[sq]); board.material[black] += ValueN; break; case 'b' : SETBIT (board.b[black][bishop], sq); SETBIT (board.blockerr90, r90[sq]); SETBIT (board.blockerr45, r45[sq]); SETBIT (board.blockerr315, r315[sq]); board.material[black] += ValueB; break; case 'r' : SETBIT (board.b[black][rook], sq); SETBIT (board.blockerr90, r90[sq]); SETBIT (board.blockerr45, r45[sq]); SETBIT (board.blockerr315, r315[sq]); board.material[black] += ValueR; break; case 'q' : SETBIT (board.b[black][queen], sq); SETBIT (board.blockerr90, r90[sq]); SETBIT (board.blockerr45, r45[sq]); SETBIT (board.blockerr315, r315[sq]); board.material[black] += ValueQ; break; case 'k' : SETBIT (board.b[black][king], sq); SETBIT (board.blockerr90, r90[sq]); SETBIT (board.blockerr45, r45[sq]); SETBIT (board.blockerr315, r315[sq]); break; case '/' : r -= 8; c = -1; break; default : break; } if (isdigit (*p)) c += (*p - '0'); else c++; /* * Special case, a trailing "/" is accepted on the * end of the board settings. */ if (r == -8 && p[1] == ' ') r = 0; if (r < 0 || c > 8) return EPD_ERROR; if (c == 8 && p[1] != '/' && p[1] != ' ') return EPD_ERROR; p++; } board.pmaterial[white] = board.material[white] - nbits(board.b[white][pawn]) * ValueP; board.pmaterial[black] = board.material[black] - nbits(board.b[black][pawn]) * ValueP; board.king[white] = leadz (board.b[white][king]); board.king[black] = leadz (board.b[black][king]); UpdateFriends (); UpdateCBoard (); UpdateMvboard (); /* Get side to move */ if (!++p) return EPD_ERROR; if (*p == 'w') board.side = white; else if (*p == 'b') board.side = black; else return EPD_ERROR; /* Isn't this one cute? */ if (!++p || *p != ' ' || !++p) return EPD_ERROR; /* Castling status */ while (p && *p != ' ') { if (*p == 'K') board.flag |= WKINGCASTLE; else if (*p == 'Q') board.flag |= WQUEENCASTLE; else if (*p == 'k') board.flag |= BKINGCASTLE; else if (*p == 'q') board.flag |= BQUEENCASTLE; else if (*p == '-') { p++; break; } else return EPD_ERROR; p++; } if (!p || *p != ' ' || !++p) return EPD_ERROR; /* * En passant square, can only be '-' or [a-h][36] * In fact, one could add more sanity checks here. */ if (*p != '-') { if (!p[1] || *p < 'a' || *p > 'h' || !(p[1] == '3' || p[1] == '6')) return EPD_ERROR; board.ep = (*p - 'a') + (p[1] - '1')*8; p++; } else { board.ep = -1; } solution[0] = '\0'; id[0] = '\0'; if (!++p) return EPD_SUCCESS; /* The opcodes are optional, so we should not generate errors here */ /* Read in best move; "bm" operator */ str_p = strstr(p, "bm"); if (str_p) sscanf (str_p, "bm %63[^;];", solution); /* Read in the description; "id" operator */ str_p = strstr(p, "id"); if (str_p) sscanf (p, "id %31[^;];", id); phase = PHASE; return EPD_SUCCESS; }