Пример #1
0
//-----------------------------------------------------------------------------
int main(int argc, char const *argv[])
{
#ifdef TEST
	test();
    return 0;
#endif // TEST

    InotifyImpl inotify("./temp");
    if (inotify.init())
        inotify.run();

    return 0;
}
Пример #2
0
int MtpStorage::createDB() {
	std::string mtpParent = "";
	mtpstorageparent = getPath();
	// root directory is special: handle 0, parent 0, and empty path
	mtpmap[0] = new Tree(0, 0, "");
	MTPD("MtpStorage::createDB DONE\n");
	if (use_mutex) {
		sendEvents = true;
		MTPD("inotify_init\n");
		inotify_fd = inotify_init();
		if (inotify_fd < 0) {
			MTPE("Can't run inotify_init for mtp server: %s\n", strerror(errno));
		} else {
			MTPD("Starting inotify thread\n");
			inotify_thread = inotify();
		}
	} else {
		MTPD("NOT starting inotify thread\n");
	}
	// for debugging and caching purposes, read the root dir already now
	readDir(mtpstorageparent, mtpmap[0]);
	// all other dirs are read on demand
	return 0;
}
Пример #3
0
void Session::ProcessPacket(SmartPacket* packet, Player* pSource)
{
    switch(packet->GetOpcode())
    {
        case CMSG_INITIATE_SESSION:
        {
            SmartPacket response(SMSG_INITIATE_SESSION_RESPONSE);
            response << uint32(sGlobalStorage->GetLock());
            SendPacket(pSource, &response);
            break;
        }
        case CMSG_VALIDATE_VERSION:
        {
            SmartPacket response(SMSG_VALIDATE_VERSION_RESPONSE);
            response << VERSION_STR;
            response << uint32(1);   // I pres to hratelny - jen doporuci update pri rozdilu verzi
            SendPacket(pSource, &response);

            break;
        }
        case CMSG_REQUEST_INSTANCE_LIST:
        {
            const char* inststr = sInstanceManager->GetInstanceString();
            SmartPacket response(SMSG_INSTANCE_LIST);
            response << inststr;
            SendPacket(pSource, &response);

            break;
        }
        case CMSG_ENTER_GAME:
        {
            uint32 instanceId;
            std::string nickname;

            *packet >> instanceId;
            nickname = packet->readstr();

            if (sSession->GetPlayerByName(nickname.c_str()))
            {
                SmartPacket response(SMSG_ENTER_GAME_RESULT);
                response << uint8(1); //error - nick uz ma nekdo jiny
                SendPacket(pSource, &response);
            }

            pSource->m_nickName = nickname;

            sInstanceManager->RegisterPlayer(pSource, instanceId);
            if (sInstanceManager->GetPlayerInstanceId(pSource) != instanceId)
            {
                SmartPacket response(SMSG_ENTER_GAME_RESULT);
                response << uint8(2); //error - nelze pridat do instance
                SendPacket(pSource, &response);
                return;
            }

            // TODO: nacteni start. pozic ze souboru
            pSource->m_positionX = 1.0f;
            pSource->m_positionY = 1.0f;

            SmartPacket response(SMSG_ENTER_GAME_RESULT);
            response << uint8(0); //vsechno ok
            response << float(pSource->m_positionX); // startovni pozice X
            response << float(pSource->m_positionY); // startovni pozice Y (klientsky Z)
            response << uint32(pSource->m_socket);   // jako ID pouzijeme socket ID
            response << instanceId;
            SendPacket(pSource, &response);

            SmartPacket mapdata(SMSG_MAP_INITIAL_DATA);

            Instance* pInstance = sInstanceManager->GetPlayerInstance(pSource);
            if (pInstance)
            {
                for (int i = 0; i < MAX_PLAYERS_PER_INSTANCE; i++)
                {
                    if (pInstance->pPlayers[i])
                    {
                        mapdata << uint32(pInstance->pPlayers[i]->m_socket);
                        mapdata << pInstance->pPlayers[i]->m_positionX;
                        mapdata << pInstance->pPlayers[i]->m_positionY;
                        mapdata << uint8(pInstance->pPlayers[i]->m_modelIdOffset);
                        mapdata << pInstance->pPlayers[i]->m_nickName.c_str();
                    }
                    else
                    {
                        mapdata << uint32(0);
                        mapdata << float(0);
                        mapdata << float(0);
                        mapdata << uint8(0);
                        mapdata << "UNKNOWN";
                    }
                }

                mapdata << uint32(pInstance->m_dynRecords.size());
                for (std::list<Instance::DynamicRecord>::const_iterator itr = pInstance->m_dynRecords.begin(); itr != pInstance->m_dynRecords.end(); ++itr)
                    mapdata << uint32((*itr).x) << uint32((*itr).y) << uint8((*itr).type);
                SendPacket(pSource, &mapdata);
            }
            SmartPacket inotify(SMSG_NEW_PLAYER);
            inotify << uint32(pSource->m_socket);       // ID
            inotify << pSource->m_positionX;            // pozice X
            inotify << pSource->m_positionY;            // pozice Y
            inotify << uint8(pSource->m_modelIdOffset); // offset modelu, klient si s tim poradi
            inotify << nickname.c_str();                // nick
            sInstanceManager->SendInstancePacket(&inotify, instanceId);
            break;
        }
        case MSG_NONE:
        default:
            sLog->ErrorOut("Received unknown/invalid opcode: %u",packet->GetOpcode());
            break;
    }
}