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


C++ CNetMessage类代码示例

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


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

示例1: netCallbacksHandler

void netCallbacksHandler(CNetMessage &msgin)
{
//	nldebug("NET: %"NL_I64"u Received message type %hu size %u", CTime::getLocalTime(), (uint16)msgin.type(), msgin.length());

	switch(msgin.type())
	{
	SWITCH_CASE(Chat);
	SWITCH_CASE(Error);
	SWITCH_CASE(Login);
	SWITCH_CASE(Logout);
	SWITCH_CASE(OpenClose);
	SWITCH_CASE(Update);
	SWITCH_CASE(UpdateOne);
	SWITCH_CASE(FullUpdate);
	SWITCH_CASE(UpdateElement);
	SWITCH_CASE(Ready);
	SWITCH_CASE(EverybodyReady);
	SWITCH_CASE(RequestDownload);
	SWITCH_CASE(RequestCRCKey);
	SWITCH_CASE(DisplayText);
	SWITCH_CASE(SessionState);
	SWITCH_CASE(StartSession);
	SWITCH_CASE(EndSession);
	SWITCH_CASE(EditMode);
	SWITCH_CASE(EnableElement);
	SWITCH_CASE(ExecLua);
	SWITCH_CASE(CollideWhenFly);
	SWITCH_CASE(TimeArrival);
	
	default: nlwarning("Received an unknown message type %hu", (uint16)msgin.type()); break;
	}
}
开发者ID:StraToN,项目名称:tux-target,代码行数:32,代码来源:net_callbacks.cpp

示例2: OnInGame

bool CNetClient::OnInGame(void *context, CFsmEvent* event)
{
	// TODO: should split each of these cases into a separate method

	CNetClient* client = (CNetClient*)context;

	CNetMessage* message = (CNetMessage*)event->GetParamRef();
	if (message)
	{
		if (message->GetType() == NMT_SIMULATION_COMMAND)
		{
			CSimulationMessage* simMessage = static_cast<CSimulationMessage*> (message);
			client->m_ClientTurnManager->OnSimulationMessage(simMessage);
		}
		else if (message->GetType() == NMT_SYNC_ERROR)
		{
			CSyncErrorMessage* syncMessage = static_cast<CSyncErrorMessage*> (message);
			client->m_ClientTurnManager->OnSyncError(syncMessage->m_Turn, syncMessage->m_HashExpected, syncMessage->m_PlayerNames);
		}
		else if (message->GetType() == NMT_END_COMMAND_BATCH)
		{
			CEndCommandBatchMessage* endMessage = static_cast<CEndCommandBatchMessage*> (message);
			client->m_ClientTurnManager->FinishedAllCommands(endMessage->m_Turn, endMessage->m_TurnLength);
		}
	}

	return true;
}
开发者ID:joselitofilho,项目名称:0ad,代码行数:28,代码来源:NetClient.cpp

示例3: cbStartSession

static void cbStartSession(CNetMessage &msgin)
{
	float timebeforestart, timeout;
	string levelName, str1, str2;
	vector<uint8> ranks;
	vector<uint8> eids;

	msgin.serial(timebeforestart, timeout, levelName, str1, str2);
	msgin.serialCont(ranks);
	msgin.serialCont(eids);
	
	nlinfo("NET: cbStartSession timebeforestart=%f timeout=%f levelName='%s' str1='%s' str2='%s'",
		timebeforestart, timeout, levelName.c_str(), str1.c_str(), str2.c_str());
	
	nlassert(ranks.size()==eids.size());

	for(uint32 i=0;i<eids.size();i++)
	{
		if(CEntityManager::getInstance().exist(eids[i]))
			CEntityManager::getInstance()[eids[i]].rank(ranks[i]);
	}

	CMtpTarget::getInstance().startSession(timebeforestart / 1000.0f, timeout / 1000.0f, levelName, str1, str2);

	/*
	msgin.serial (mtpTarget::getInstance().Interface2d.LevelName);
	msgin.serial (mtpTarget::getInstance().Interface2d.FullLevelName);
	msgin.serial (mtpTarget::getInstance().Interface2d.string1);
	msgin.serial (mtpTarget::getInstance().Interface2d.string2);
	msgin.serial (mtpTarget::getInstance().Interface2d.Author);

	mtpTarget::getInstance().startSession(timebeforestart / 1000, timeout / 1000, mtpTarget::getInstance().Interface2d.LevelName);
*/
  
}
开发者ID:StraToN,项目名称:tux-target,代码行数:35,代码来源:net_callbacks.cpp

示例4: serialIn8_8fp

float serialIn8_8fp(CNetMessage &msgin)
{
	uint8 sx;
	uint8 rdx;
	msgin.serial(sx);
	msgin.serial(rdx);
	
	return convert8_8fp(sx,rdx);
}
开发者ID:StraToN,项目名称:tux-target,代码行数:9,代码来源:custom_floating_point.cpp

示例5: cbUpdateList

static void cbUpdateList(CNetMessage &msgin)
{
	CEntityManager::getInstance().updateListId.clear();
	while(msgin.getPos() < (sint32)msgin.length())
	{
		uint8 eid;
		msgin.serial(eid);
		CEntityManager::getInstance().updateListId.push_back(eid);
	}
}
开发者ID:StraToN,项目名称:tux-target,代码行数:10,代码来源:net_callbacks.cpp

示例6: cbChat

static void cbChat(CNetMessage &msgin)
{
	nlinfo("NET: cbChat");
	string msg;
	while(msgin.getPos() < (sint32)msgin.length())
	{
		msgin.serial(msg);
		CChatTask::getInstance().addLine(msg);
		if(SessionFile) 
			fprintf(SessionFile, "%hu CH %s\n",0, msg.c_str());
	}
}
开发者ID:StraToN,项目名称:tux-target,代码行数:12,代码来源:net_callbacks.cpp

示例7: handleClients

void handleClients()
{
    CNetMessage* msg;
    int channel;
    if(udpclient->Receive(msg, channel))
    {
        if(msg->getType()=='h')
        {
            hero_pos pos;
            msg->UnLoadByte(pos.x, pos.y, pos.id);
            if(pos.id!=myId)
            {
                int oriX = heroGroup[pos.id]->getX();
                int oriY = heroGroup[pos.id]->getY();
                heroGroup[pos.id]->setCoords(pos.x, pos.y);
                int frame = heroGroup[pos.id]->getFrame();
                if (pos.y<oriY) {
                    frame++;
                    if (frame>2)
                        frame = 0;
                    heroGroup[pos.id]->setAnimFrame(frame+6);
                }
                else if (pos.x>oriX) {
                    frame++;
                    if (frame>2)
                        frame = 0;
                    heroGroup[pos.id]->setAnimFrame(frame+3);
                }
                else if (pos.y>oriY) {
                    frame++;
                    if (frame>2)
                        frame = 0;
                    heroGroup[pos.id]->setAnimFrame(frame);
                }
                else if (pos.x<oriX) {
                    frame++;
                    if (frame>2)
                        frame = 0;
                    heroGroup[pos.id]->setAnimFrame(frame+9);
                }
                heroGroup[pos.id]->setFrame(frame);
            }
        } else if(msg->getType()=='b')
        {
            int bx, by, lvl;
            msg->UnLoadByte(bx, by, lvl);
            Bomb* newbomb=new Bomb(bx, by, 4000, SDL_GetTicks(), lvl);
            bombGroup.push_back(newbomb);
        }

    }
    delete msg;
}
开发者ID:HuiD,项目名称:ece590,代码行数:53,代码来源:main.cpp

示例8: OnInGame

bool CNetServerWorker::OnInGame(void* context, CFsmEvent* event)
{
	// TODO: should split each of these cases into a separate method

	CNetServerSession* session = (CNetServerSession*)context;
	CNetServerWorker& server = session->GetServer();

	CNetMessage* message = (CNetMessage*)event->GetParamRef();
	if (message->GetType() == (uint)NMT_SIMULATION_COMMAND)
	{
		CSimulationMessage* simMessage = static_cast<CSimulationMessage*> (message);

		// Ignore messages sent by one player on behalf of another player
		// unless cheating is enabled
		bool cheatsEnabled = false;
		ScriptInterface& scriptInterface = server.GetScriptInterface();
		JSContext* cx = scriptInterface.GetContext();
		JSAutoRequest rq(cx);
		JS::RootedValue settings(cx);
		scriptInterface.GetProperty(server.m_GameAttributes.get(), "settings", &settings);
		if (scriptInterface.HasProperty(settings, "CheatsEnabled"))
			scriptInterface.GetProperty(settings, "CheatsEnabled", cheatsEnabled);

		PlayerAssignmentMap::iterator it = server.m_PlayerAssignments.find(session->GetGUID());
		// When cheating is disabled, fail if the player the message claims to
		// represent does not exist or does not match the sender's player name
		if (!cheatsEnabled && (it == server.m_PlayerAssignments.end() || it->second.m_PlayerID != simMessage->m_Player))
			return true;

		// Send it back to all clients immediately
		server.Broadcast(simMessage);

		// Save all the received commands
		if (server.m_SavedCommands.size() < simMessage->m_Turn + 1)
			server.m_SavedCommands.resize(simMessage->m_Turn + 1);
		server.m_SavedCommands[simMessage->m_Turn].push_back(*simMessage);

		// TODO: we shouldn't send the message back to the client that first sent it
	}
	else if (message->GetType() == (uint)NMT_SYNC_CHECK)
	{
		CSyncCheckMessage* syncMessage = static_cast<CSyncCheckMessage*> (message);
		server.m_ServerTurnManager->NotifyFinishedClientUpdate(session->GetHostID(), session->GetUserName(), syncMessage->m_Turn, syncMessage->m_Hash);
	}
	else if (message->GetType() == (uint)NMT_END_COMMAND_BATCH)
	{
		CEndCommandBatchMessage* endMessage = static_cast<CEndCommandBatchMessage*> (message);
		server.m_ServerTurnManager->NotifyFinishedClientCommands(session->GetHostID(), endMessage->m_Turn);
	}

	return true;
}
开发者ID:svifylabs,项目名称:0ad,代码行数:52,代码来源:NetServer.cpp

示例9: cbEditMode

static void cbEditMode(CNetMessage &msgin)
{
	uint8 editMode;
	msgin.serial(editMode);
	nlinfo("NET: cbEditMode editMode=%hu", (uint16)editMode);

	// TODO: what is the goal of this function???
}
开发者ID:StraToN,项目名称:tux-target,代码行数:8,代码来源:net_callbacks.cpp

示例10: Send

/**
 * @brief Enviar un paquete encapsulado en un objeto del tipo CNetMessage
 *
 * @param sData Estructura de donde se sacarán los datos a enviar.
 *
 * @return Si se ha podido enviar algo, devolverá true. En caso contrario, devolverá false (llamada no bloqueante).
 */
bool CClientSocket::Send (CNetMessage& sData) {
//check if there is a socket
    if (m_Socket == NULL)
        return false;
    charbuf buf;
    int len;

//Check if the instance can send bytes, if it can, unload the number of bytes specified by NumToLoad() virtual function
    while ((len = sData.NumToUnLoad()) > 0) {
        sData.UnLoadBytes (buf);
        if (SDLNet_TCP_Send(m_Socket, (void *)buf, len) < len) {
            std::cerr << "SDLNet_TCP_Send: " << SDLNet_GetError() << std::endl;
            return false;
        }
    }
    return true;
}
开发者ID:wikiti,项目名称:ullPong,代码行数:24,代码来源:CNet.cpp

示例11: cbSessionState

static void cbSessionState(CNetMessage &msgin)
{
	string sn;
	msgin.serial(sn);
	nlinfo("NET: cbSessionState sn='%s'", sn.c_str());

	// TODO: what is the goal of this function???
}
开发者ID:StraToN,项目名称:tux-target,代码行数:8,代码来源:net_callbacks.cpp

示例12: Receive

/**
 * @brief Recibir un paquete encapsulado en un objeto del tipo CNetMessage
 *
 * @param rData Estructura donde se van a almacenar los datos recibidos.
 *
 * @return Si se ha recibido algo, devolverá true. En caso de no recibir nada, devolverá false (llamada no bloqueante).
 *
 * Una vez recibido el mensaje, se cambia su estado a FULL.
 */
bool CClientSocket::Receive(CNetMessage& rData) {
//Firstly, check if there is a socket
    if (m_Socket == NULL)
        return false;
    charbuf buf;

//Check if the instance can receive bytes, if it can, load the number of bytes specified by NumToLoad() virtual function
    while (rData.NumToLoad() > 0) {
        if (SDLNet_TCP_Recv(m_Socket, buf, rData.NumToLoad()) > 0) {
            rData.LoadBytes (buf, rData.NumToLoad());
        }
        else {
            return false;
        }
    }
    rData.finish();
    return true;
}
开发者ID:wikiti,项目名称:ullPong,代码行数:27,代码来源:CNet.cpp

示例13: cbExecLua

static void cbExecLua(CNetMessage &msgin)
{
	string luaCode;
	msgin.serial(luaCode);
	nlinfo("NET: cbExecLua luaCode='%s'", luaCode.c_str());

	if(CLevelManager::getInstance().levelPresent())
		CLevelManager::getInstance().currentLevel().execLuaCode(luaCode);
}
开发者ID:StraToN,项目名称:tux-target,代码行数:9,代码来源:net_callbacks.cpp

示例14: cbRequestCRCKey

static void cbRequestCRCKey(CNetMessage &msgin)
{
	string fn;
	CHashKey hashKey;
	msgin.serial(fn, hashKey);
	nlinfo("NET: cbRequestCRCKey fn='%s' hashKey='%s'", fn.c_str(), hashKey.toString().c_str());

	CResourceManagerLan::getInstance().receivedCRC(fn);
}
开发者ID:StraToN,项目名称:tux-target,代码行数:9,代码来源:net_callbacks.cpp

示例15: cbEnableElement

static void cbEnableElement(CNetMessage &msgin)
{
	uint8 elementId;
	bool enabled;
	msgin.serial(elementId, enabled);
	nlinfo("NET: cbEnableElement");
	
	if(CLevelManager::getInstance().levelPresent())
		CLevelManager::getInstance().currentLevel().getModule(elementId)->enabled(enabled);
}
开发者ID:StraToN,项目名称:tux-target,代码行数:10,代码来源:net_callbacks.cpp


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