Beispiel #1
0
bool oEvent::msSynchronize(oBase *ob)
{
  //if (!msSynchronizeRead) return true;
  if (!HasDBConnection && !HasPendingDBConnection)
    return true;

  int ret = msSynchronizeRead(ob);

  char err[256];
  if (msGetErrorState(err))
    gdibase.addInfoBox("sqlerror", err, 15000);

  if (ret==0) {
    verifyConnection();
    return false;
  }

  if (typeid(*ob)==typeid(oTeam)) {
    static_cast<pTeam>(ob)->apply(false, 0, false);
  }

  if (ret==1) {
    gdibase.RemoveFirstInfoBox("sqlwarning");
    gdibase.addInfoBox("sqlwarning", "Varning: ändringar i X blev överskrivna#" + ob->getInfo(), 5000);
  }
  return ret!=0;
}
Beispiel #2
0
bool oEvent::synchronizeList(oListId id, bool preSyncEvent, bool postSyncEvent) {
  if (!HasDBConnection)
    return true;

  if (preSyncEvent) {
    msSynchronize(this);
    resetSQLChanged(true, false);
  }

  if ( !msSynchronizeList(this, id) ) {
    verifyConnection();
    return false;
  }

  if (id == oLPunchId)
    advanceInformationPunches.clear();

  if (postSyncEvent) {
    reEvaluateChanged();
    resetChangeStatus();
    return true;
  }

  return true;
}
Beispiel #3
0
/*
 * This is a simple cover method for the sending of a message to the
 * IRC server. The 'aDest' can be a channel or a user.
 */
void CKIRCProtocol::sendMessage( const CKString & aDest, const CKString & aMsg )
{
	bool		error = false;

	// first, check to see if we have anything to do
	if (!error) {
		if (aDest.size() == 0) {
			error = true;
			std::ostringstream	msg;
			msg << "CKIRCProtocol::sendMessage(const CKString &, const CKString &)"
				" - the supplied chat destination is empty, and that means that "
				"there's nothing I can do. Please make sure that there is a valid "
				"destination before calling this method.";
			throw CKException(__FILE__, __LINE__, msg.str());
		}
	}
	if (!error) {
		if (aMsg.size() == 0) {
			error = true;
			std::ostringstream	msg;
			msg << "CKIRCProtocol::sendMessage(const CKString &, const CKString &)"
				" - the supplied chat message is empty, and that means that "
				"there's nothing I can do. Please make sure that there is a valid "
				"destination before calling this method.";
			throw CKException(__FILE__, __LINE__, msg.str());
		}
	}

	/*
	 * Make sure we have a connection to the server, if not, then see if
	 * we did, and if we did, then reconnect.
	 */
	if (!error) {
		if (!verifyConnection()) {
			error = true;
			std::ostringstream	msg;
			msg << "CKIRCProtocol::sendMessage(const CKString &, const CKString &)"
				" - while trying to send the message to the IRC server, the "
				"connection to the IRC server at " << mHostname << ":" << mPort <<
				" seemed to be down, and trying to re-establish it was not possible. "
				"Please check into this as soon as possible.";
			throw CKException(__FILE__, __LINE__, msg.str());
		}
	}

	// if the destination is a channel, make sure we're joined
	if (!error) {
		if (aDest[0] == '#') {
			doJOIN(aDest);
		}
	}

	/*
	 * Now we need to process each line, but be careful, if the line's
	 * length exceeds the MAX_MESSAGE_LEN, it needs to be broken on the
	 * word boundaries to make it fit.
	 */
	if (!error) {
		CKString	line;
		int			size = aMsg.size();
		int			sol = 0;
		int			eol = 0;
		while (sol < size) {
			// clear out the current line buffer
			line.clear();
			// find the next eod-of-line character in the message
			eol = aMsg.find('\n', sol);
			if (eol == -1) {
				// not there, so the rest of the message is all there is
				line = aMsg.substr(sol);
				sol = aMsg.length();
			} else {
				// got it, so get the line and then move past it
				line = aMsg.substr(sol, (eol - sol));
				sol = eol + 1;
			}

			/*
			 * If we have a string to send, then send it. But watch
			 * out for lines that are too long...
			 */
			while (line.length() > MAX_MESSAGE_LEN) {
				// try to cut it right at the limit
				int		pos = MAX_MESSAGE_LEN;
				// but make a break at a space in the message
				while ((line[pos] != ' ') && (pos > 0)) {
					pos--;
				}
				// if there was no break, then be harsh, but fair
				if (pos == 0) {
					pos = MAX_MESSAGE_LEN;
				}
				// send out the first part of the line
				doPRIVMSG(aDest, line.substr(0, pos));
				// update what's left of the line to send
				line.erase(0, (pos + 1));
			}
			// whatever's left is OK to send out
			if (line.length() > 0) {
				doPRIVMSG(aDest, line);
			}
		}
	}
}