当前位置: 首页>>代码示例>>C++>>正文


C++ DB::removeMessage方法代码示例

本文整理汇总了C++中DB::removeMessage方法的典型用法代码示例。如果您正苦于以下问题:C++ DB::removeMessage方法的具体用法?C++ DB::removeMessage怎么用?C++ DB::removeMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DB的用法示例。


在下文中一共展示了DB::removeMessage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: HandlePacket

bool HandlePacket (Packet& request, Packet& response) {
	int uid, mid;
	if (request.getType() == PacketType::LOGIN_REQUEST) {
		response.setType(PacketType::LOGIN_RESPONSE);
		if (request.getData().size() == 2 && (uid = db.logIn(request.getData()[0], request.getData()[1])) != -1) {
			__uint64_t sid = ((((__uint64_t) rand () & 0x77777777) << 32) | (rand () & 0x77777777));
			sids [sid] = uid;
			response.setSID(sid);
			response.getData().push_back("1");
		} else {
			response.getData().push_back("0");
		}
		return true;
	}
	auto it = sids.find(request.getSID());
	if (it == sids.end ()) {
		response.setType(request.getType() + 1);
		response.setSID (0);
		return true;
	}
	response.setSID(request.getSID());
	uid = it-> second;
	switch (request.getType()) {
	case PacketType::LOGOUT_REQUEST:
		response.setType(PacketType::LOGOUT_RESPONSE);
		sids.erase(request.getSID());
		response.getData().push_back("1");
		return true;
	case PacketType::LATEST_REQUEST:
		response.setType(PacketType::LATEST_RESPONSE);
		response.getData().push_back(db.latestCheck(uid));
		return true;
	case PacketType::PULL_REQUEST:
		response.setType(PacketType::PULL_RESPONSE);
		if (request.getData().size() == 1) {
			try {
				mid = stoi (request.getData()[0]);
				string msg = db.readMessage(uid, mid);
				response.getData().push_back(msg);
			} catch (exception& ex) { printf ("%s\r\n", ex. what ()); }
		}
		return true;
	case PacketType::REMOVE_REQUEST:
		response.setType(PacketType::REMOVE_RESPONSE);
		if (request.getData().size() == 1) {
			try {
				mid = stoi (request.getData()[0]);
				if (db.removeMessage(uid, mid)) {
					response.getData().push_back("1");
					return true;
				}
			} catch (exception& ex) { printf ("%s\r\n", ex. what ()); }
		}
		response.getData().push_back("0");
		return true;
	case PacketType::SEND_REQUEST:
		response.setType(PacketType::SEND_RESPONSE);
		if (request.getData().size() == 2 && db.sendMessage(uid, request.getData()[0], request.getData()[1])) {
			response.getData().push_back("1");
			return true;
		}
		response.getData().push_back("0");
		return true;
	case PacketType::NEWMESSAGES_REQUEST:
		response.setType(PacketType::NEWMESSAGES_RESPONSE);
		for (string id : db.listUnreadMessages(uid)) {
			response.getData().push_back(id);
		}
		return true;
	case PacketType::LISTMESSAGES_REQUEST:
		response.setType(PacketType::LISTMESSAGES_RESPONSE);
		for (string id : db.listAllMessages(uid)) {
			response.getData().push_back(id);
		}
		return true;
	case PacketType::LISTSENTMESSAGES_REQUEST:
		response.setType(PacketType::LISTSENTMESSAGES_RESPONSE);
		for (string id : db.listSentMessages(uid)) {
			response.getData().push_back(id);
		}
		return true;
	default:
		return false;
	}
}
开发者ID:kalecky,项目名称:Hoochat,代码行数:85,代码来源:Server.cpp


注:本文中的DB::removeMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。