本文整理汇总了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;
}
}
示例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;
}
示例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);
*/
}
示例4: serialIn8_8fp
float serialIn8_8fp(CNetMessage &msgin)
{
uint8 sx;
uint8 rdx;
msgin.serial(sx);
msgin.serial(rdx);
return convert8_8fp(sx,rdx);
}
示例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);
}
}
示例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());
}
}
示例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;
}
示例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;
}
示例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???
}
示例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;
}
示例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???
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}