本文整理汇总了C++中IslMessage类的典型用法代码示例。如果您正苦于以下问题:C++ IslMessage类的具体用法?C++ IslMessage怎么用?C++ IslMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IslMessage类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readClient
void IslInterface::readClient()
{
QByteArray data = socket->readAll();
server->incRxBytes(data.size());
inputBuffer.append(data);
do {
if (!messageInProgress) {
if (inputBuffer.size() >= 4) {
messageLength = (((quint32) (unsigned char) inputBuffer[0]) << 24)
+ (((quint32) (unsigned char) inputBuffer[1]) << 16)
+ (((quint32) (unsigned char) inputBuffer[2]) << 8)
+ ((quint32) (unsigned char) inputBuffer[3]);
inputBuffer.remove(0, 4);
messageInProgress = true;
} else
return;
}
if (inputBuffer.size() < messageLength)
return;
IslMessage newMessage;
newMessage.ParseFromArray(inputBuffer.data(), messageLength);
inputBuffer.remove(0, messageLength);
messageInProgress = false;
processMessage(newMessage);
} while (!inputBuffer.isEmpty());
}
示例2: sigSendIslMessage
void Server::sendIsl_RoomEvent(const RoomEvent &item, int serverId, qint64 sessionId)
{
IslMessage msg;
msg.set_message_type(IslMessage::ROOM_EVENT);
if (sessionId != -1)
msg.set_session_id(sessionId);
msg.mutable_room_event()->CopyFrom(item);
emit sigSendIslMessage(msg, serverId);
}
示例3: transmitMessage
void IslInterface::transmitMessage(const IslMessage &item)
{
QByteArray buf;
unsigned int size = item.ByteSize();
buf.resize(size + 4);
item.SerializeToArray(buf.data() + 4, size);
buf.data()[3] = (unsigned char) size;
buf.data()[2] = (unsigned char) (size >> 8);
buf.data()[1] = (unsigned char) (size >> 16);
buf.data()[0] = (unsigned char) (size >> 24);
outputBufferMutex.lock();
outputBuffer.append(buf);
outputBufferMutex.unlock();
emit outputBufferChanged();
}
示例4: deleteLater
void IslInterface::initServer()
{
socket->setSocketDescriptor(socketDescriptor);
logger->logMessage(QString("[ISL] incoming connection: %1").arg(socket->peerAddress().toString()));
QList<ServerProperties> serverList = server->getServerList();
int listIndex = -1;
for (int i = 0; i < serverList.size(); ++i)
if (serverList[i].address == socket->peerAddress()) {
listIndex = i;
break;
}
if (listIndex == -1) {
logger->logMessage(QString("[ISL] address %1 unknown, terminating connection").arg(socket->peerAddress().toString()));
deleteLater();
return;
}
socket->startServerEncryption();
if (!socket->waitForEncrypted(5000)) {
QList<QSslError> sslErrors(socket->sslErrors());
if (sslErrors.isEmpty())
qDebug() << "[ISL] SSL handshake timeout, terminating connection";
else
qDebug() << "[ISL] SSL errors:" << sslErrors;
deleteLater();
return;
}
if (serverList[listIndex].cert == socket->peerCertificate())
logger->logMessage(QString("[ISL] Peer authenticated as " + serverList[listIndex].hostname));
else {
logger->logMessage(QString("[ISL] Authentication failed, terminating connection"));
deleteLater();
return;
}
serverId = serverList[listIndex].id;
Event_ServerCompleteList event;
event.set_server_id(server->getServerId());
server->clientsLock.lockForRead();
QMapIterator<QString, Server_ProtocolHandler *> userIterator(server->getUsers());
while (userIterator.hasNext())
event.add_user_list()->CopyFrom(userIterator.next().value()->copyUserInfo(true, true));
server->clientsLock.unlock();
server->roomsLock.lockForRead();
QMapIterator<int, Server_Room *> roomIterator(server->getRooms());
while (roomIterator.hasNext()) {
Server_Room *room = roomIterator.next().value();
room->usersLock.lockForRead();
room->gamesLock.lockForRead();
room->getInfo(*event.add_room_list(), true, true, false, false);
}
IslMessage message;
message.set_message_type(IslMessage::SESSION_EVENT);
SessionEvent *sessionEvent = message.mutable_session_event();
sessionEvent->GetReflection()->MutableMessage(sessionEvent, event.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(event);
server->islLock.lockForWrite();
if (server->islConnectionExists(serverId)) {
qDebug() << "[ISL] Duplicate connection to #" << serverId << "terminating connection";
deleteLater();
} else {
transmitMessage(message);
server->addIslInterface(serverId, this);
}
server->islLock.unlock();
roomIterator.toFront();
while (roomIterator.hasNext()) {
roomIterator.next();
roomIterator.value()->gamesLock.unlock();
roomIterator.value()->usersLock.unlock();
}
server->roomsLock.unlock();
}
示例5: qDebug
void IslInterface::processMessage(const IslMessage &item)
{
qDebug() << QString::fromStdString(item.DebugString());
switch (item.message_type()) {
case IslMessage::ROOM_COMMAND_CONTAINER: {
processRoomCommand(item.room_command(), item.session_id());
break;
}
case IslMessage::GAME_COMMAND_CONTAINER: {
emit gameCommandContainerReceived(item.game_command(), item.player_id(), serverId, item.session_id());
break;
}
case IslMessage::SESSION_EVENT: {
processSessionEvent(item.session_event(), item.session_id());
break;
}
case IslMessage::RESPONSE: {
emit responseReceived(item.response(), item.session_id());
break;
}
case IslMessage::GAME_EVENT_CONTAINER: {
emit gameEventContainerReceived(item.game_event_container(), item.session_id());
break;
}
case IslMessage::ROOM_EVENT: {
processRoomEvent(item.room_event()); break;
break;
}
default: ;
}
}