bool PeerConnector::ConnectUDP(const PEER_ADDRESS& addr, const PeerConnectParam& param) { if (m_LiveInfo.TransferMethod == TRANSFER_TCP) { return ConnectTCP(addr, 0, param); // 用于测试纯tcp的情况 } if ( addr.UdpPort == 0 ) return false; if (CheckConnected(addr, param.IsVIP)) { VIEW_INFO("CPeerManager::ConnectToRemote CheckConnected " << addr << " failed"); return false; } const PEER_ADDRESS& localAddr = m_NetInfo->Address; if (addr.IP == localAddr.IP && addr.UdpPort == localAddr.UdpPort) { //LIVE_ASSERT(false); VIEW_ERROR("ConnectUDP ignore myself " << addr); return false; } return m_UDPConnector->Connect(addr, param); }
bool TopologicalGraph::FindPlanarMap() {if(planarMap() < 0){if(debug())DebugPrintf(" EXIST planarMap < 0");return false;} bool Connect= CheckConnected(); if(planarMap() == 1) {if(debug())DebugPrintf(" EXIST planarMap = 1"); return true; } if(Connect && ComputeGenus() == 0) {if(debug())DebugPrintf("Good Genus"); planarMap() = 1;return true; } if(Connect && Set(tvertex()).exist(PROP_COORD)) // Geometric Graph {GeometricGraph GG(*this); if(debug())DebugPrintf("Executing geometric cir"); Prop1<int> maptype(Set(),PROP_MAPTYPE,0); int _maptype = maptype(); svector<tbrin> cir0,acir0; cir0 = cir; acir0 = acir; if(GG.ComputeGeometricCir() == 0) {if(debug())DebugPrintf("Using geometric map"); planarMap() = 1;return true; } maptype() = _maptype; cir.vector() = cir0; acir.vector() = acir0; } if(debug())DebugPrintf("FindPlanarMap:LRALGO"); int ret = Planarity(); if(ret == 1){planarMap() = 1; return true;} else planarMap() = -1; return false; }
bool CMUSHclientDoc::ProcessOneAliasSequence (const CString strCurrentLine, const bool bCountThem, bool & bOmitFromLog, bool & bEchoAlias, CAliasList & AliasList, OneShotItemMap & mapOneShotItems) { for (int iAlias = 0; iAlias < GetAliasArray ().GetSize (); iAlias++) { CAlias * alias_item = GetAliasArray () [iAlias]; // ignore non-enabled aliases if (!alias_item->bEnabled) continue; m_iAliasesEvaluatedCount++; BOOL bMatched; // empty wildcards now for (int i = 0; i < MAX_WILDCARDS; i++) alias_item->wildcards [i] = ""; CString strTarget = strCurrentLine; try { bMatched = regexec (alias_item->regexp, strTarget); } catch(CException* e) { e->ReportError (); e->Delete (); bMatched = false; } if (!bMatched) // no match, try next one continue; m_iAliasesMatchedCount++; m_iAliasesMatchedThisSessionCount++; if (alias_item->bOneShot) mapOneShotItems.push_back ( OneShotItem (m_CurrentPlugin, (const char *) alias_item->strInternalName)); // if alias wants it, omit entire typed line from command history if (alias_item->bOmitFromCommandHistory) m_bOmitFromCommandHistory = true; alias_item->wildcards.clear (); for (int iWildcard = 0; iWildcard < MAX_WILDCARDS; iWildcard++) alias_item->wildcards.push_back ( FixWildcard (alias_item->regexp->GetWildcard (iWildcard), false, alias_item->iSendTo, m_strLanguage) ); // echo the alias they typed, unless command echo off, or previously displayed // (if wanted - v3.38) if (bEchoAlias && // not already done alias_item->bEchoAlias) // alias wants to be echoed { DisplayMsg (strCurrentLine + ENDLINE, strCurrentLine.GetLength () + strlen (ENDLINE), USER_INPUT | (LoggingInput () ? LOG_LINE : 0)); bEchoAlias = false; // don't echo the same line twice // and log the command the actually typed if (LoggingInput ()) LogCommand (strCurrentLine); } if (bCountThem) alias_item->nMatched++; // count alias matches bOmitFromLog = alias_item->bOmitFromLog; alias_item->tWhenMatched = CTime::GetCurrentTime(); // when it matched if (alias_item->strLabel.IsEmpty ()) Trace ("Matched alias \"%s\"", (LPCTSTR) alias_item->name); else Trace ("Matched alias %s", (LPCTSTR) alias_item->strLabel); // if we have to do parameter substitution on the alias, do it now CString strSendText; // copy contents to strSendText area, replacing %1, %2 etc. with appropriate contents try { strSendText = FixSendText (::FixupEscapeSequences (alias_item->contents), alias_item->iSendTo, // where it is going alias_item->regexp, // regexp GetLanguage (), // eg. vbscript false, // lower-case wildcards alias_item->bExpandVariables, // expand variables true, // expand wildcards false, // convert regexps false, // is it regexp or normal? true); // throw exceptions } catch (CException* e) { e->ReportError(); e->Delete(); return true; } AliasList.AddTail (alias_item); // add to list of aliases CString strExtraOutput; // let them know if they are foolishly trying to send to a closed connection // - only applies to commands that actually send to the world if (!strSendText.IsEmpty ()) switch (alias_item->iSendTo) { case eSendToWorld: case eSendToCommandQueue: case eSendToSpeedwalk: case eSendImmediate: if (CheckConnected ()) return true; break; } alias_item->bExecutingScript = true; // cannot be deleted now SendTo (alias_item->iSendTo, strSendText, alias_item->bOmitFromOutput, alias_item->bOmitFromLog, TFormat ("Alias: %s", (LPCTSTR) alias_item->strLabel), alias_item->strVariable, strExtraOutput); alias_item->bExecutingScript = false; // can be deleted now // display any stuff sent to output window if (!strExtraOutput.IsEmpty ()) DisplayMsg (strExtraOutput, strExtraOutput.GetLength (), COMMENT); // only re-match if they want multiple matches if (!alias_item->bKeepEvaluating) break; } // end of looping, checking each alias return FALSE; } // end of CMUSHclientDoc::ProcessOneAliasSequence
BOOL CMUSHclientDoc::EvaluateCommand (const CString & full_input, const bool bCountThem, bool & bOmitFromLog, const bool bTest) { CString str; POSITION pos; CString input = full_input; CAliasList AliasList; // get rid of any carriage returns input.Replace ("\r", ""); // ignore blank lines ?? is this wise? if (input.IsEmpty ()) return false; // ------------------------- SPEED WALKING ------------------------------ // see if they are doing speed walking if (m_enable_speed_walk && input.Left (m_speed_walk_prefix.GetLength ()) == m_speed_walk_prefix) { CString strEvaluatedSpeedwalk = DoEvaluateSpeedwalk (input.Mid (m_speed_walk_prefix.GetLength ())); if (!strEvaluatedSpeedwalk.IsEmpty ()) { if (strEvaluatedSpeedwalk [0] == '*') // error in speedwalk string? { ::UMessageBox (strEvaluatedSpeedwalk.Mid (1)); return true; } // let them know if they are foolishly trying to send to a closed connection if (CheckConnected ()) return true; SendMsg (strEvaluatedSpeedwalk, m_display_my_input, true, // queue it LoggingInput ()); } return false; } // end of having a speed-walk string // here if not speed walking // --------------------------- ALIASES ------------------------------ bool bEchoAlias = m_display_my_input; OneShotItemMap mapOneShotItems; if (m_enable_aliases) { m_CurrentPlugin = NULL; if (ProcessOneAliasSequence (input, bCountThem, bOmitFromLog, bEchoAlias, AliasList, mapOneShotItems)) return true; // do plugins for (pos = m_PluginList.GetHeadPosition (); pos; ) { m_CurrentPlugin = m_PluginList.GetNext (pos); if (m_CurrentPlugin->m_bEnabled) if (ProcessOneAliasSequence (input, bCountThem, bOmitFromLog, bEchoAlias, AliasList, mapOneShotItems)) { m_CurrentPlugin = NULL; return true; } } // end of doing each plugin m_CurrentPlugin = NULL; // not in a plugin any more } // end of aliases enabled // if no alias matched at all, just send the raw command if (AliasList.IsEmpty ()) { // let them know if they are foolishly trying to send to a closed connection if (CheckConnected ()) return true; // don't reconnect on a deliberate QUIT if (input.CompareNoCase (m_macros [MAC_QUIT]) == 0) m_bDisconnectOK = true; // don't want reconnect on quit SendMsg (input, m_display_my_input, false, LoggingInput ()); // send now return FALSE; } // execute any scripts associated with aliases we found bool bFoundIt; CAlias * existing_alias_item; CAlias * alias_item; CString strAliasName; for (pos = AliasList.GetHeadPosition (); pos; ) { alias_item = AliasList.GetNext (pos); bFoundIt = false; // check that alias still exists, in case a script deleted it - and also // to work out which plugin it is in m_CurrentPlugin = NULL; // main aliases - if main scripting active for (POSITION pos = GetAliasMap ().GetStartPosition (); !bFoundIt && pos; ) { GetAliasMap ().GetNextAssoc (pos, strAliasName, existing_alias_item); if (existing_alias_item == alias_item) { bFoundIt = true; // execute Alias script ExecuteAliasScript (alias_item, input); } } // end of scanning main aliases // do plugins for (POSITION plugin_pos = m_PluginList.GetHeadPosition (); !bFoundIt && plugin_pos; ) { m_CurrentPlugin = m_PluginList.GetNext (plugin_pos); if (m_CurrentPlugin->m_bEnabled) for (POSITION pos = GetAliasMap ().GetStartPosition (); !bFoundIt && pos; ) { GetAliasMap ().GetNextAssoc (pos, strAliasName, existing_alias_item); if (existing_alias_item == alias_item) { bFoundIt = true; // execute Alias script ExecuteAliasScript (alias_item, input); } } // end of scanning plugin aliases } // end of doing plugins list } // end of list of aliass that fired // now that we have run all scripts etc., delete one-shot aliases int iDeletedCount = 0; int iDeletedNonTemporaryCount = 0; for (OneShotItemMap::const_iterator one_shot_it = mapOneShotItems.begin (); one_shot_it != mapOneShotItems.end (); one_shot_it++) { CAlias * alias_item; CString strAliasName = one_shot_it->sItemKey.c_str (); m_CurrentPlugin = one_shot_it->pWhichPlugin; // set back to correct plugin if (!GetAliasMap ().Lookup (strAliasName, alias_item)) continue; // can't if executing a script if (alias_item->bExecutingScript) continue; if (!m_CurrentPlugin && !alias_item->bTemporary) iDeletedNonTemporaryCount++; iDeletedCount++; // the alias seems to exist - delete its pointer delete alias_item; // now delete its entry GetAliasMap ().RemoveKey (strAliasName); } // end of deleting one-shot items if (iDeletedCount > 0) { SortAliases (); if (iDeletedNonTemporaryCount > 0) // plugin mods don't really count SetModifiedFlag (TRUE); // document has changed } m_CurrentPlugin = NULL; return FALSE; } // end of CMUSHclientDoc::EvaluateCommand