本文整理汇总了C++中Network::IsClient方法的典型用法代码示例。如果您正苦于以下问题:C++ Network::IsClient方法的具体用法?C++ Network::IsClient怎么用?C++ Network::IsClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Network
的用法示例。
在下文中一共展示了Network::IsClient方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReceiveActions
void NetworkThread::ReceiveActions()
{
char* buffer;
size_t packet_size;
Network* net = Network::GetInstance();
std::list<DistantComputer*>::iterator dst_cpu;
std::list<DistantComputer*>& cpu = net->GetRemoteHosts();
// While the connection is up
while (Continue()) {
if (net->GetState() == WNet::NETWORK_PLAYING && cpu.empty()) {
// If while playing everybody disconnected, just quit
break;
}
//Loop while nothing is received
while (Continue()) {
IndexServer::GetInstance()->Refresh();
// Check forced disconnections
dst_cpu = cpu.begin();
while (Continue() && dst_cpu != cpu.end()) {
// Disconnection is in 2 phases to be handled by one thread
if ((*dst_cpu)->MustBeDisconnected()) {
net->CloseConnection(dst_cpu);
dst_cpu = cpu.begin();
}
else
dst_cpu++;
}
// List is now maybe empty
if (cpu.empty() && net->IsClient()) {
fprintf(stderr, "you are alone!\n");
Stop();
return; // We really don't need to go through the loops
}
net->WaitActionSleep();
int num_ready = net->CheckActivity(100);
// Means something is available
if (num_ready>0)
break;
// Means an error
else if (num_ready == -1) {
//Spams a lot under windows without the errno check...
fprintf(stderr, "SDLNet_CheckSockets: %s\n", SDLNet_GetError());
continue; //Or break?
}
}
for (dst_cpu = cpu.begin();
Continue() && dst_cpu != cpu.end();
dst_cpu++) {
// Check if this socket contains data to receive
if ((*dst_cpu)->SocketReady()) {
if (!(*dst_cpu)->ReceiveData(&buffer, &packet_size)) {
// An error occured during the reception
(*dst_cpu)->ForceDisconnection();
continue;
}
if (!buffer && !packet_size) {
// Client is valid but there is not yet enough data to read an action
continue;
}
#ifdef LOG_NETWORK
if (fin != 0) {
int tmp = 0xFFFFFFFF;
write(fin, &packet_size, 4);
write(fin, buffer, packet_size);
write(fin, &tmp, 4);
}
#endif
Action* a = new Action(buffer, (*dst_cpu));
free(buffer);
MSG_DEBUG("network.traffic", "Received action %s",
ActionHandler::GetActionName(a->GetType()).c_str());
net->HandleAction(a, *dst_cpu);
}
}
}
}
示例2: ui_HandleKeypress
//.........这里部分代码省略.........
if(g_modalMessage) {
Message *msg = g_modalMessage->GetMessage();
if(g_theMessagePool->IsValid(*msg)) {
Assert(msg->IsAlertBox());
MessageData *data = msg->AccessData();
if(data->GetNumButtons() <= 2 && data->GetNumButtons() > 0) {
data->GetButton(0)->Callback();
}
}
} else if(g_utilityTextMessage) {
g_utilityTextMessage->m_callback(FALSE);
g_utilityTextMessage->RemoveWindow();
} else {
if(g_selected_item->GetVisiblePlayer() == g_selected_item->GetCurPlayer()) {
DPRINTF(k_DBG_GAMESTATE, ("Keypress end turn, %d\n", g_selected_item->GetCurPlayer()));
g_selected_item->RegisterManualEndTurn();
g_director->AddEndTurn();
}
else
{
}
}
break;
case KEY_FUNCTION_SAVE_WORLD :
if (g_civApp->IsGameLoaded() && !g_network.IsClient()) {
g_civApp->AutoSave(g_selected_item->GetVisiblePlayer(), true);
}
move = FALSE ;
break ;
case KEY_FUNCTION_LOAD_WORLD :
if (g_civApp->IsGameLoaded() && !g_network.IsActive()) {
{
g_civApp->PostLoadQuickSaveAction(g_selected_item->GetVisiblePlayer());
}
move = FALSE ;
}
break ;
case KEY_FUNCTION_QUIT:
optionwarningscreen_displayMyWindow(OWS_QUIT);
return 1;
break;